aboutsummaryrefslogtreecommitdiff
path: root/benches/benchmarks/async_measurement_overhead.rs
blob: 0c9605a178c9804a303997e064e0d757fa3c8597 (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
37
38
39
40
41
42
43
44
45
46
47
48
use criterion::{async_executor::FuturesExecutor, criterion_group, BatchSize, Criterion};

fn some_benchmark(c: &mut Criterion) {
    let mut group = c.benchmark_group("async overhead");
    group.bench_function("iter", |b| b.to_async(FuturesExecutor).iter(|| async { 1 }));
    group.bench_function("iter_with_setup", |b| {
        b.to_async(FuturesExecutor)
            .iter_with_setup(|| (), |_| async { 1 })
    });
    group.bench_function("iter_with_large_setup", |b| {
        b.to_async(FuturesExecutor)
            .iter_with_large_setup(|| (), |_| async { 1 })
    });
    group.bench_function("iter_with_large_drop", |b| {
        b.to_async(FuturesExecutor)
            .iter_with_large_drop(|| async { 1 })
    });
    group.bench_function("iter_batched_small_input", |b| {
        b.to_async(FuturesExecutor)
            .iter_batched(|| (), |_| async { 1 }, BatchSize::SmallInput)
    });
    group.bench_function("iter_batched_large_input", |b| {
        b.to_async(FuturesExecutor)
            .iter_batched(|| (), |_| async { 1 }, BatchSize::LargeInput)
    });
    group.bench_function("iter_batched_per_iteration", |b| {
        b.to_async(FuturesExecutor)
            .iter_batched(|| (), |_| async { 1 }, BatchSize::PerIteration)
    });
    group.bench_function("iter_batched_ref_small_input", |b| {
        b.to_async(FuturesExecutor)
            .iter_batched_ref(|| (), |_| async { 1 }, BatchSize::SmallInput)
    });
    group.bench_function("iter_batched_ref_large_input", |b| {
        b.to_async(FuturesExecutor)
            .iter_batched_ref(|| (), |_| async { 1 }, BatchSize::LargeInput)
    });
    group.bench_function("iter_batched_ref_per_iteration", |b| {
        b.to_async(FuturesExecutor).iter_batched_ref(
            || (),
            |_| async { 1 },
            BatchSize::PerIteration,
        )
    });
    group.finish();
}

criterion_group!(benches, some_benchmark);