• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use criterion::{async_executor::FuturesExecutor, criterion_group, BatchSize, Criterion};
2 
some_benchmark(c: &mut Criterion)3 fn some_benchmark(c: &mut Criterion) {
4     let mut group = c.benchmark_group("async overhead");
5     group.bench_function("iter", |b| b.to_async(FuturesExecutor).iter(|| async { 1 }));
6     group.bench_function("iter_with_setup", |b| {
7         b.to_async(FuturesExecutor)
8             .iter_with_setup(|| (), |_| async { 1 })
9     });
10     group.bench_function("iter_with_large_setup", |b| {
11         b.to_async(FuturesExecutor)
12             .iter_with_large_setup(|| (), |_| async { 1 })
13     });
14     group.bench_function("iter_with_large_drop", |b| {
15         b.to_async(FuturesExecutor)
16             .iter_with_large_drop(|| async { 1 })
17     });
18     group.bench_function("iter_batched_small_input", |b| {
19         b.to_async(FuturesExecutor)
20             .iter_batched(|| (), |_| async { 1 }, BatchSize::SmallInput)
21     });
22     group.bench_function("iter_batched_large_input", |b| {
23         b.to_async(FuturesExecutor)
24             .iter_batched(|| (), |_| async { 1 }, BatchSize::LargeInput)
25     });
26     group.bench_function("iter_batched_per_iteration", |b| {
27         b.to_async(FuturesExecutor)
28             .iter_batched(|| (), |_| async { 1 }, BatchSize::PerIteration)
29     });
30     group.bench_function("iter_batched_ref_small_input", |b| {
31         b.to_async(FuturesExecutor)
32             .iter_batched_ref(|| (), |_| async { 1 }, BatchSize::SmallInput)
33     });
34     group.bench_function("iter_batched_ref_large_input", |b| {
35         b.to_async(FuturesExecutor)
36             .iter_batched_ref(|| (), |_| async { 1 }, BatchSize::LargeInput)
37     });
38     group.bench_function("iter_batched_ref_per_iteration", |b| {
39         b.to_async(FuturesExecutor).iter_batched_ref(
40             || (),
41             |_| async { 1 },
42             BatchSize::PerIteration,
43         )
44     });
45     group.finish();
46 }
47 
48 criterion_group!(benches, some_benchmark);
49