Add spawn bench

This commit is contained in:
Alexander Polakov 2020-05-05 01:43:36 +03:00
parent 11da938867
commit 24a2a107d3
2 changed files with 26 additions and 0 deletions

View File

@ -49,9 +49,14 @@ wepoll-binding = "2.0.0"
[dev-dependencies]
num_cpus = "1.13.0"
tempfile = "3.1.0"
criterion = "0.3"
[workspace]
members = [
".",
"examples",
]
[[bench]]
name = "spawn"
harness = false

21
benches/spawn.rs Normal file
View File

@ -0,0 +1,21 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use futures::future;
use smol::Task;
pub fn spawn_benchmark(c: &mut Criterion) {
std::thread::spawn(|| smol::run(future::pending::<()>()));
c.bench_function("spawn time", |b| {
b.iter(|| {
let x = black_box(5);
smol::block_on(async {
Task::spawn(async move {
let _ = x + 1;
})
.await;
});
})
});
}
criterion_group!(benches, spawn_benchmark);
criterion_main!(benches);