aboutsummaryrefslogtreecommitdiff
path: root/benches/benchmarks/iter_with_large_drop.rs
blob: ee9a8e9322a2d5e70c0eb903a0685ae13ceafe75 (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
31
32
33
34
35
36
#![allow(deprecated)]

use criterion::{criterion_group, Benchmark, Criterion, Throughput};
use std::time::Duration;

const SIZE: usize = 1024 * 1024;

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

fn small_drop(c: &mut Criterion) {
    c.bench(
        "iter_with_large_drop",
        Benchmark::new("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
}