use criterion::{black_box, criterion_group, criterion_main, Criterion}; use dyn_future::DynFuture; use futures::future::{self, FutureExt}; use rayon::prelude::*; use std::pin::Pin; fn run_boxed(n: u64) -> Vec>> { (0..131072) .into_par_iter() .map(|_| DynFuture::new(future::ready(n).then(|n| future::ready(n * 2)))) .collect() } fn criterion_benchmark(c: &mut Criterion) { c.bench_function("dyn-future", |b| b.iter(|| run_boxed(black_box(20)))); } criterion_group!(benches, criterion_benchmark); criterion_main!(benches);