Nadja Reitzenstein 55d6609e33 Executor compiles
2021-11-14 17:51:48 +01:00

68 lines
1.5 KiB
Rust

#![feature(test)]
extern crate test;
use bastion_executor::blocking;
use lightproc::proc_stack::ProcStack;
use std::thread;
use std::time::Duration;
use test::Bencher;
#[cfg(feature = "tokio-runtime")]
mod tokio_benchs {
use super::*;
#[bench]
fn blocking(b: &mut Bencher) {
tokio_test::block_on(async { _blocking(b) });
}
#[bench]
fn blocking_single(b: &mut Bencher) {
tokio_test::block_on(async {
_blocking_single(b);
});
}
}
#[cfg(not(feature = "tokio-runtime"))]
mod no_tokio_benchs {
use super::*;
#[bench]
fn blocking(b: &mut Bencher) {
_blocking(b);
}
#[bench]
fn blocking_single(b: &mut Bencher) {
_blocking_single(b);
}
}
// Benchmark for a 10K burst task spawn
fn _blocking(b: &mut Bencher) {
b.iter(|| {
(0..10_000)
.map(|_| {
blocking::spawn_blocking(
async {
let duration = Duration::from_millis(1);
thread::sleep(duration);
},
ProcStack::default(),
)
})
.collect::<Vec<_>>()
});
}
// Benchmark for a single blocking task spawn
fn _blocking_single(b: &mut Bencher) {
b.iter(|| {
blocking::spawn_blocking(
async {
let duration = Duration::from_millis(1);
thread::sleep(duration);
},
ProcStack::default(),
)
});
}