| 1 | use criterion::{criterion_group, BatchSize, Criterion, Throughput}; |
| 2 | use std::time::Duration; |
| 3 | |
| 4 | const SIZE: usize = 1024 * 1024; |
| 5 | |
| 6 | fn large_setup(c: &mut Criterion) { |
| 7 | let mut group = c.benchmark_group("iter_with_large_setup" ); |
| 8 | group.throughput(Throughput::Bytes(SIZE as u64)); |
| 9 | group.bench_function("large_setup" , |b| { |
| 10 | b.iter_batched( |
| 11 | || (0..SIZE).map(|i| i as u8).collect::<Vec<_>>(), |
| 12 | |v| v, |
| 13 | BatchSize::NumBatches(1), |
| 14 | ) |
| 15 | }); |
| 16 | } |
| 17 | |
| 18 | fn small_setup(c: &mut Criterion) { |
| 19 | let mut group = c.benchmark_group("iter_with_large_setup" ); |
| 20 | group.bench_function("small_setup" , |b| { |
| 21 | b.iter_batched(|| SIZE, |size| size, BatchSize::NumBatches(1)) |
| 22 | }); |
| 23 | } |
| 24 | |
| 25 | fn short_warmup() -> Criterion { |
| 26 | Criterion::default().warm_up_time(Duration::new(1, 0)) |
| 27 | } |
| 28 | |
| 29 | criterion_group! { |
| 30 | name = benches; |
| 31 | config = short_warmup(); |
| 32 | targets = large_setup, small_setup |
| 33 | } |
| 34 | |