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

65 lines
1.6 KiB
Rust
Raw Normal View History

use executor::load_balancer;
use executor::prelude::*;
2021-11-14 17:51:48 +01:00
use futures_timer::Delay;
use std::time::Duration;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
2021-11-14 17:51:48 +01:00
#[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);
}
2021-11-14 17:51:48 +01:00
}
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();
b.bench_function("spawn_lot", |b| b.iter(|| {
2021-11-14 17:51:48 +01:00
let _ = (0..10_000)
.map(|_| {
executor.spawn(
2021-11-14 17:51:48 +01:00
async {
let duration = Duration::from_millis(1);
Delay::new(duration).await;
},
)
})
.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();
b.bench_function("spawn single", |b| b.iter(|| {
executor.spawn(
2021-11-14 17:51:48 +01:00
async {
let duration = Duration::from_millis(1);
Delay::new(duration).await;
},
);
}));
2021-11-14 17:51:48 +01:00
}