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