use std::time::Duration; use criterion::Criterion; use tempfile::{tempdir, TempDir}; pub fn temp_dir() -> TempDir { tempdir().unwrap() } // Configure a Criterion struct to perform really fast benchmarks. This is not // recommended for real benchmarking, only for testing. pub fn short_benchmark(dir: &TempDir) -> Criterion { Criterion::default() .output_directory(dir.path()) .warm_up_time(Duration::from_millis(25)) .measurement_time(Duration::from_millis(250)) .nresamples(2000) } /// Only used in tests and doctests #[allow(unused)] pub fn run_short_bench(b: F) where F: FnOnce(&mut Criterion) { let dir = temp_dir(); let mut c = short_benchmark(&dir); b(&mut c); }