use criterion::{
black_box, criterion_group, criterion_main, Criterion, ParameterizedBenchmark, Throughput,
};
use dashcache::{DashCache, GlobalCache};
use elysees::Arc;
use lazy_static::lazy_static;
use rand::{thread_rng, Rng};
pub type GlobalCacheTy = DashCache<Arc<usize>>;
lazy_static! {
pub static ref GLOBAL_CACHE: GlobalCacheTy = DashCache::new();
}
pub fn criterion_benchmark(c: &mut Criterion) {
c.bench(
"cache",
ParameterizedBenchmark::new(
"randint",
|b, (ops, max)| {
let mut rng = thread_rng();
b.iter(|| {
for _ in 0..*ops {
black_box(GLOBAL_CACHE.cache(rng.gen_range(0, max)));
}
})
},
vec![
(1000, 100),
(1000, 400),
(1000, 1600),
(1000, 6400),
(1000, 128000),
],
)
.throughput(|(ops, _)| Throughput::Elements(*ops as u64)),
);
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);