2021-11-25 23:36:17 +01:00
|
|
|
use executor::load_balancer;
|
|
|
|
use executor::prelude::*;
|
2021-11-14 17:51:48 +01:00
|
|
|
use futures_timer::Delay;
|
|
|
|
use std::time::Duration;
|
2021-11-25 23:36:17 +01:00
|
|
|
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
2021-11-14 17:51:48 +01:00
|
|
|
|
|
|
|
#[cfg(feature = "tokio-runtime")]
|
2021-11-25 23:36:17 +01:00
|
|
|
mod benches {
|
2021-11-14 17:51:48 +01:00
|
|
|
use super::*;
|
2021-11-25 23:36:17 +01:00
|
|
|
pub fn spawn_lot(b: &mut Bencher) {
|
2021-11-14 17:51:48 +01:00
|
|
|
tokio_test::block_on(async { _spawn_lot(b) });
|
|
|
|
}
|
2021-11-25 23:36:17 +01:00
|
|
|
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"))]
|
2021-11-25 23:36:17 +01:00
|
|
|
mod benches {
|
2021-11-14 17:51:48 +01:00
|
|
|
use super::*;
|
2021-11-25 23:36:17 +01:00
|
|
|
|
|
|
|
pub fn spawn_lot(b: &mut Criterion) {
|
2021-11-14 17:51:48 +01:00
|
|
|
_spawn_lot(b);
|
|
|
|
}
|
2021-11-25 23:36:17 +01:00
|
|
|
pub fn spawn_single(b: &mut Criterion) {
|
2021-11-14 17:51:48 +01:00
|
|
|
_spawn_single(b);
|
|
|
|
}
|
2021-11-25 23:36:17 +01:00
|
|
|
|
2021-11-14 17:51:48 +01:00
|
|
|
}
|
|
|
|
|
2021-11-25 23:36:17 +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
|
2021-11-25 23:36:17 +01:00
|
|
|
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(|_| {
|
2021-11-25 23:36:17 +01:00
|
|
|
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-25 23:36:17 +01:00
|
|
|
}));
|
2021-11-14 17:51:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Benchmark for a single task spawn
|
2021-11-25 23:36:17 +01:00
|
|
|
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-25 23:36:17 +01:00
|
|
|
}));
|
2021-11-14 17:51:48 +01:00
|
|
|
}
|