show_operations/
show_operations.rs

1extern crate subset_map;
2
3use subset_map::*;
4use std::time::Instant;
5
6fn main() {
7    let elements: Vec<_> = (0..17).collect();
8    let start = Instant::now();
9
10    let mut n = 0;
11    let map = SubsetMap::fill(&elements, |_x| {
12        n += 1;
13        n
14    });
15
16    println!(
17        "[CREATE_SIMPLE]: Combinations: {}(Size: {}) -> Time: {:?}",
18        n,
19        map.size(),
20        start.elapsed()
21    );
22
23    drop(map);
24
25    let start = Instant::now();
26
27    let mut n = 0usize;
28    let mut combinations = Vec::new();
29    let map = SubsetMap::fill(&elements, |x| {
30        combinations.push(x.to_vec());
31        n += 1;
32        n
33    });
34
35    println!(
36        "[CREATE_FOR_QUERY]: Combinations: {}(Size: {}) -> Time: {:?}",
37        n,
38        map.size(),
39        start.elapsed()
40    );
41
42    let start = Instant::now();
43
44    let mut n = 0usize;
45    for combination in combinations {
46        if let Some(_p) = map.get(&combination) {
47            n += 1;
48        }
49    }
50
51    println!(
52        "[GET]: Combinations: {} -> Time: {:?} {}",
53        map.size(),
54        start.elapsed(),
55        n
56    );
57
58    drop(map);
59
60    let mut n = 0usize;
61    let mut combinations = Vec::new();
62    let map = SubsetMap::fill(&elements, |x| {
63        combinations.push(x.to_vec());
64        n += 1;
65        n
66    });
67
68    let start = Instant::now();
69
70    let mut n = 0usize;
71    for combination in combinations {
72        if let LookupResult::Perfect(Some(_p)) = map.lookup(&combination) {
73            n += 1;
74        }
75    }
76
77    println!(
78        "[LOOKUP]: Combinations: {} -> Time: {:?} {}",
79        map.size(),
80        start.elapsed(),
81        n
82    );
83
84    drop(map);
85
86    let mut n = 0usize;
87    let mut combinations = Vec::new();
88    let map = SubsetMap::fill(&elements, |x| {
89        combinations.push(x.to_vec());
90        n += 1;
91        n
92    });
93
94    let start = Instant::now();
95
96    let mut n = 0usize;
97    for combination in combinations {
98        if let FindResult::Perfect(_) = map.find(&combination) {
99            n += 1;
100        }
101    }
102
103    println!(
104        "[FIND]: Combinations: {} -> Time: {:?} {}",
105        map.size(),
106        start.elapsed(),
107        n
108    );
109}