fabaccess-bffh/runtime/executor/benches/spawn.rs

64 lines
1.6 KiB
Rust
Raw Normal View History

2022-05-05 15:50:44 +02:00
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use executor::load_balancer;
use executor::prelude::*;
2021-11-14 17:51:48 +01:00
use futures_timer::Delay;
use std::time::Duration;
#[cfg(feature = "tokio-runtime")]
mod benches {
2021-11-14 17:51:48 +01:00
use super::*;
pub fn spawn_lot(b: &mut Bencher) {
2021-11-14 17:51:48 +01:00
tokio_test::block_on(async { _spawn_lot(b) });
}
pub fn spawn_single(b: &mut Bencher) {
2021-11-14 17:51:48 +01:00
tokio_test::block_on(async {
_spawn_single(b);
});
}
}
#[cfg(not(feature = "tokio-runtime"))]
mod benches {
2021-11-14 17:51:48 +01:00
use super::*;
pub fn spawn_lot(b: &mut Criterion) {
2021-11-14 17:51:48 +01:00
_spawn_lot(b);
}
pub fn spawn_single(b: &mut Criterion) {
2021-11-14 17:51:48 +01:00
_spawn_single(b);
}
}
criterion_group!(spawn, benches::spawn_lot, benches::spawn_single);
criterion_main!(spawn);
2021-11-14 17:51:48 +01:00
// Benchmark for a 10K burst task spawn
fn _spawn_lot(b: &mut Criterion) {
let executor = Executor::new();
2022-05-05 15:50:44 +02:00
b.bench_function("spawn_lot", |b| {
b.iter(|| {
let _ = (0..10_000)
.map(|_| {
executor.spawn(async {
2021-11-14 17:51:48 +01:00
let duration = Duration::from_millis(1);
Delay::new(duration).await;
2022-05-05 15:50:44 +02:00
})
})
.collect::<Vec<_>>();
})
});
2021-11-14 17:51:48 +01:00
}
// Benchmark for a single task spawn
fn _spawn_single(b: &mut Criterion) {
let executor = Executor::new();
2022-05-05 15:50:44 +02:00
b.bench_function("spawn single", |b| {
b.iter(|| {
executor.spawn(async {
2021-11-14 17:51:48 +01:00
let duration = Duration::from_millis(1);
Delay::new(duration).await;
2022-05-05 15:50:44 +02:00
});
})
});
2021-11-14 17:51:48 +01:00
}