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