mirror of https://github.com/stjepang/smol
Add spawn bench
This commit is contained in:
parent
11da938867
commit
24a2a107d3
|
@ -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
|
|
@ -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);
|
Loading…
Reference in New Issue