]> git.proxmox.com Git - rustc.git/blame - src/vendor/itertools/benches/tuple_combinations.rs
New upstream version 1.31.0+dfsg1
[rustc.git] / src / vendor / itertools / benches / tuple_combinations.rs
CommitLineData
abe05a73
XL
1#![feature(test)]
2
3extern crate test;
4extern crate itertools;
5
6use test::{black_box, Bencher};
7use itertools::Itertools;
8
9// aproximate 100_000 iterations for each combination
10const N1: usize = 100_000;
11const N2: usize = 448;
12const N3: usize = 86;
13const N4: usize = 41;
14
15#[bench]
16fn comb_for1(b: &mut Bencher) {
17 b.iter(|| {
18 for i in 0..N1 {
19 black_box(i);
20 }
21 });
22}
23
24#[bench]
25fn comb_for2(b: &mut Bencher) {
26 b.iter(|| {
27 for i in 0..N2 {
28 for j in (i + 1)..N2 {
29 black_box(i + j);
30 }
31 }
32 });
33}
34
35#[bench]
36fn comb_for3(b: &mut Bencher) {
37 b.iter(|| {
38 for i in 0..N3 {
39 for j in (i + 1)..N3 {
40 for k in (j + 1)..N3 {
41 black_box(i + j + k);
42 }
43 }
44 }
45 });
46}
47
48#[bench]
49fn comb_for4(b: &mut Bencher) {
50 b.iter(|| {
51 for i in 0..N4 {
52 for j in (i + 1)..N4 {
53 for k in (j + 1)..N4 {
54 for l in (k + 1)..N4 {
55 black_box(i + j + k + l);
56 }
57 }
58 }
59 }
60 });
61}
62
63#[bench]
64fn comb_c1(b: &mut Bencher) {
65 b.iter(|| {
66 for (i,) in (0..N1).tuple_combinations() {
67 black_box(i);
68 }
69 });
70}
71
72#[bench]
73fn comb_c2(b: &mut Bencher) {
74 b.iter(|| {
75 for (i, j) in (0..N2).tuple_combinations() {
76 black_box(i + j);
77 }
78 });
79}
80
81#[bench]
82fn comb_c3(b: &mut Bencher) {
83 b.iter(|| {
84 for (i, j, k) in (0..N3).tuple_combinations() {
85 black_box(i + j + k);
86 }
87 });
88}
89
90#[bench]
91fn comb_c4(b: &mut Bencher) {
92 b.iter(|| {
93 for (i, j, k, l) in (0..N4).tuple_combinations() {
94 black_box(i + j + k + l);
95 }
96 });
97}