1 | use criterion::{criterion_group, BatchSize, Criterion}; |
2 | |
3 | fn some_benchmark(c: &mut Criterion) { |
4 | let mut group = c.benchmark_group("overhead" ); |
5 | group.bench_function("iter" , |b| b.iter(|| 1)); |
6 | group.bench_function("iter_with_setup" , |b| b.iter_with_setup(|| (), |_| 1)); |
7 | group.bench_function("iter_with_large_setup" , |b| { |
8 | b.iter_batched(|| (), |_| 1, BatchSize::NumBatches(1)) |
9 | }); |
10 | group.bench_function("iter_with_large_drop" , |b| b.iter_with_large_drop(|| 1)); |
11 | group.bench_function("iter_batched_small_input" , |b| { |
12 | b.iter_batched(|| (), |_| 1, BatchSize::SmallInput) |
13 | }); |
14 | group.bench_function("iter_batched_large_input" , |b| { |
15 | b.iter_batched(|| (), |_| 1, BatchSize::LargeInput) |
16 | }); |
17 | group.bench_function("iter_batched_per_iteration" , |b| { |
18 | b.iter_batched(|| (), |_| 1, BatchSize::PerIteration) |
19 | }); |
20 | group.bench_function("iter_batched_ref_small_input" , |b| { |
21 | b.iter_batched_ref(|| (), |_| 1, BatchSize::SmallInput) |
22 | }); |
23 | group.bench_function("iter_batched_ref_large_input" , |b| { |
24 | b.iter_batched_ref(|| (), |_| 1, BatchSize::LargeInput) |
25 | }); |
26 | group.bench_function("iter_batched_ref_per_iteration" , |b| { |
27 | b.iter_batched_ref(|| (), |_| 1, BatchSize::PerIteration) |
28 | }); |
29 | group.finish(); |
30 | } |
31 | |
32 | criterion_group!(benches, some_benchmark); |
33 | |