aboutsummaryrefslogtreecommitdiff
path: root/benches/benchmarks/iter_with_large_drop.rs
blob: ee01de057af030f3929d811b0806165a0d100c29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use criterion::{criterion_group, Criterion, Throughput};
use std::time::Duration;

const SIZE: usize = 1024 * 1024;

fn large_drop(c: &mut Criterion) {
    let mut group = c.benchmark_group("iter_with_large_drop");
    group.throughput(Throughput::Bytes(SIZE as u64));
    group.bench_function("large_drop", |b| {
        let v: Vec<_> = (0..SIZE).map(|i| i as u8).collect();
        b.iter_with_large_drop(|| v.clone());
    });
}

fn small_drop(c: &mut Criterion) {
    let mut group = c.benchmark_group("iter_with_large_drop");
    group.bench_function("small_drop", |b| {
        b.iter_with_large_drop(|| SIZE);
    });
}

fn short_warmup() -> Criterion {
    Criterion::default().warm_up_time(Duration::new(1, 0))
}

criterion_group! {
    name = benches;
    config = short_warmup();
    targets = large_drop, small_drop
}