Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add benchmarks for Combinations iterator for combination lengths of 1, 2, 3, 4 and 14. Renames tuple_combinations test functions to tuple_comb_* for clarity in test results.
- Loading branch information
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,3 +71,7 @@ harness = false | |
[[bench]] | ||
name = "combinations" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "powerset" | ||
harness = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use itertools::Itertools; | ||
|
||
// Keep aggregate generated elements the same, regardless of powerset length. | ||
const TOTAL_ELEMENTS: usize = 1 << 16; | ||
const fn calc_iters(n: usize) -> usize { | ||
TOTAL_ELEMENTS / (1 << n) | ||
} | ||
|
||
fn powerset_n(c: &mut Criterion, n: usize) { | ||
let id = format!("powerset {}", n); | ||
c.bench_function(id.as_str(), move |b| { | ||
b.iter(|| { | ||
for _ in 0..calc_iters(n) { | ||
for elt in (0..n).powerset() { | ||
black_box(elt); | ||
} | ||
} | ||
}) | ||
}); | ||
} | ||
|
||
fn powerset_0(c: &mut Criterion) { powerset_n(c, 0); } | ||
|
||
fn powerset_1(c: &mut Criterion) { powerset_n(c, 1); } | ||
|
||
fn powerset_2(c: &mut Criterion) { powerset_n(c, 2); } | ||
|
||
fn powerset_3(c: &mut Criterion) { powerset_n(c, 3); } | ||
|
||
fn powerset_4(c: &mut Criterion) { powerset_n(c, 4); } | ||
|
||
fn powerset_5(c: &mut Criterion) { powerset_n(c, 5); } | ||
|
||
fn powerset_6(c: &mut Criterion) { powerset_n(c, 6); } | ||
|
||
fn powerset_7(c: &mut Criterion) { powerset_n(c, 7); } | ||
|
||
fn powerset_8(c: &mut Criterion) { powerset_n(c, 8); } | ||
|
||
fn powerset_9(c: &mut Criterion) { powerset_n(c, 9); } | ||
|
||
fn powerset_10(c: &mut Criterion) { powerset_n(c, 10); } | ||
|
||
fn powerset_11(c: &mut Criterion) { powerset_n(c, 11); } | ||
|
||
fn powerset_12(c: &mut Criterion) { powerset_n(c, 12); } | ||
|
||
fn powerset_13(c: &mut Criterion) { powerset_n(c, 13); } | ||
|
||
fn powerset_14(c: &mut Criterion) { powerset_n(c, 14); } | ||
|
||
fn powerset_15(c: &mut Criterion) { powerset_n(c, 15); } | ||
|
||
fn powerset_16(c: &mut Criterion) { powerset_n(c, 16); } | ||
|
||
criterion_group!( | ||
benches, | ||
powerset_0, | ||
powerset_1, | ||
powerset_2, | ||
powerset_3, | ||
powerset_4, | ||
powerset_5, | ||
powerset_6, | ||
powerset_7, | ||
powerset_8, | ||
powerset_9, | ||
powerset_10, | ||
powerset_11, | ||
powerset_12, | ||
powerset_13, | ||
powerset_14, | ||
powerset_15, | ||
powerset_16, | ||
); | ||
criterion_main!(benches); |