2019-12-24 18:34:47 -05:00
|
|
|
//! Benchmark spawning a task onto the basic and threaded Tokio executors.
|
|
|
|
|
//! This essentially measure the time to enqueue a task in the local and remote
|
|
|
|
|
//! case.
|
|
|
|
|
|
|
|
|
|
use bencher::{black_box, Bencher};
|
|
|
|
|
|
|
|
|
|
async fn work() -> usize {
|
|
|
|
|
let val = 1 + 1;
|
|
|
|
|
black_box(val)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn basic_scheduler_local_spawn(bench: &mut Bencher) {
|
2020-08-27 20:05:48 -04:00
|
|
|
let runtime = tokio::runtime::Builder::new()
|
2019-12-24 18:34:47 -05:00
|
|
|
.basic_scheduler()
|
|
|
|
|
.build()
|
|
|
|
|
.unwrap();
|
|
|
|
|
runtime.block_on(async {
|
|
|
|
|
bench.iter(|| {
|
|
|
|
|
let h = tokio::spawn(work());
|
|
|
|
|
black_box(h);
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn threaded_scheduler_local_spawn(bench: &mut Bencher) {
|
2020-08-27 20:05:48 -04:00
|
|
|
let runtime = tokio::runtime::Builder::new()
|
2019-12-24 18:34:47 -05:00
|
|
|
.threaded_scheduler()
|
|
|
|
|
.build()
|
|
|
|
|
.unwrap();
|
|
|
|
|
runtime.block_on(async {
|
|
|
|
|
bench.iter(|| {
|
|
|
|
|
let h = tokio::spawn(work());
|
|
|
|
|
black_box(h);
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn basic_scheduler_remote_spawn(bench: &mut Bencher) {
|
|
|
|
|
let runtime = tokio::runtime::Builder::new()
|
|
|
|
|
.basic_scheduler()
|
|
|
|
|
.build()
|
|
|
|
|
.unwrap();
|
2020-08-27 20:05:48 -04:00
|
|
|
|
2019-12-24 18:34:47 -05:00
|
|
|
bench.iter(|| {
|
2020-08-27 20:05:48 -04:00
|
|
|
let h = runtime.spawn(work());
|
2019-12-24 18:34:47 -05:00
|
|
|
black_box(h);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn threaded_scheduler_remote_spawn(bench: &mut Bencher) {
|
|
|
|
|
let runtime = tokio::runtime::Builder::new()
|
|
|
|
|
.threaded_scheduler()
|
|
|
|
|
.build()
|
|
|
|
|
.unwrap();
|
2020-08-27 20:05:48 -04:00
|
|
|
|
2019-12-24 18:34:47 -05:00
|
|
|
bench.iter(|| {
|
2020-08-27 20:05:48 -04:00
|
|
|
let h = runtime.spawn(work());
|
2019-12-24 18:34:47 -05:00
|
|
|
black_box(h);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bencher::benchmark_group!(
|
2020-01-27 23:48:35 -05:00
|
|
|
spawn,
|
2019-12-24 18:34:47 -05:00
|
|
|
basic_scheduler_local_spawn,
|
|
|
|
|
threaded_scheduler_local_spawn,
|
|
|
|
|
basic_scheduler_remote_spawn,
|
|
|
|
|
threaded_scheduler_remote_spawn
|
|
|
|
|
);
|
|
|
|
|
|
2020-01-27 23:48:35 -05:00
|
|
|
bencher::benchmark_main!(spawn);
|