-
Notifications
You must be signed in to change notification settings - Fork 293
/
combinations.rs
107 lines (95 loc) · 1.94 KB
/
combinations.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#![feature(test)]
extern crate test;
extern crate itertools;
use test::{black_box, Bencher};
use itertools::Itertools;
// approximate 100_000 iterations for each combination
const N1: usize = 100_000;
const N2: usize = 448;
const N3: usize = 86;
const N4: usize = 41;
const N14: usize = 21;
#[bench]
fn combs_for01(b: &mut Bencher) {
b.iter(|| {
for i in 0..N1 {
black_box(vec![i]);
}
});
}
#[bench]
fn combs_for02(b: &mut Bencher) {
b.iter(|| {
for i in 0..N2 {
for j in (i + 1)..N2 {
black_box(vec![i, j]);
}
}
});
}
#[bench]
fn combs_for03(b: &mut Bencher) {
b.iter(|| {
for i in 0..N3 {
for j in (i + 1)..N3 {
for k in (j + 1)..N3 {
black_box(vec![i, j, k]);
}
}
}
});
}
#[bench]
fn combs_for04(b: &mut Bencher) {
b.iter(|| {
for i in 0..N4 {
for j in (i + 1)..N4 {
for k in (j + 1)..N4 {
for l in (k + 1)..N4 {
black_box(vec![i, j, k, l]);
}
}
}
}
});
}
#[bench]
fn combs_c01(b: &mut Bencher) {
b.iter(|| {
for combo in (0..N1).combinations(1) {
black_box(combo);
}
});
}
#[bench]
fn combs_c02(b: &mut Bencher) {
b.iter(|| {
for combo in (0..N2).combinations(2) {
black_box(combo);
}
});
}
#[bench]
fn combs_c03(b: &mut Bencher) {
b.iter(|| {
for combo in (0..N3).combinations(3) {
black_box(combo);
}
});
}
#[bench]
fn combs_c04(b: &mut Bencher) {
b.iter(|| {
for combo in (0..N4).combinations(4) {
black_box(combo);
}
});
}
#[bench]
fn combs_c14(b: &mut Bencher) {
b.iter(|| {
for combo in (0..N14).combinations(14) {
black_box(combo);
}
});
}