use std::hint::black_box;
use criterion::measurement::WallTime;
use criterion::{BenchmarkGroup, BenchmarkId, Throughput};
pub const LARGE: usize = 8192;
pub const SMALL: usize = 32;
pub fn sizes(threshold: usize) -> [(&'static str, usize); 3] {
[("small", SMALL), ("threshold", threshold), ("large", LARGE)]
}
pub const fn crossover_sizes() -> [usize; 4] {
[256, 512, 1_024, 2_048]
}
pub fn threads() -> usize {
rayon::current_num_threads()
}
pub fn pair<I, O>(
group: &mut BenchmarkGroup<'_, WallTime>,
case: &str,
rows: usize,
input: &I,
operation: impl Fn(&I, bool) -> O,
) {
group.throughput(Throughput::Elements(rows as u64));
group.bench_with_input(BenchmarkId::new(case, "serial"), input, |bencher, input| {
bencher.iter(|| black_box(operation(black_box(input), false)));
});
let parallel = format!("parallel-{}t", threads());
group.bench_with_input(BenchmarkId::new(case, parallel), input, |bencher, input| {
bencher.iter(|| black_box(operation(black_box(input), true)));
});
}