tests: stop spawning a new tokio runtime every benchmark iteration

This commit is contained in:
Kat Marchán 2023-01-28 14:11:09 -08:00
parent 526386ada8
commit 7afcb8d649
No known key found for this signature in database
GPG Key ID: AEB529C08A3C7E9E
2 changed files with 8 additions and 1 deletions

View File

@ -37,6 +37,7 @@ walkdir = "2.3.2"
[dev-dependencies]
criterion = "0.4.0"
lazy_static = "1.4.0"
tokio = { version = "1.12.0", features = [
"fs",
"io-util",

View File

@ -5,13 +5,19 @@ use tokio::fs as afs;
#[cfg(all(test, feature = "async-std"))]
pub use async_std::task::block_on;
#[cfg(all(test, feature = "tokio"))]
lazy_static::lazy_static! {
static ref TOKIO_RUNTIME: tokio::runtime::Runtime = tokio::runtime::Runtime::new().unwrap();
}
#[cfg(all(test, feature = "tokio"))]
#[inline]
pub fn block_on<F, T>(future: F) -> T
where
F: std::future::Future<Output = T>,
{
tokio::runtime::Runtime::new().unwrap().block_on(future)
TOKIO_RUNTIME.block_on(future)
}
use std::fs::{self, File};