(c: &mut Criterion)
| 4 | use rand::Rng; |
| 5 | |
| 6 | fn criterion_benchmark(c: &mut Criterion) { |
| 7 | let mut group = c.benchmark_group("lru cache"); |
| 8 | |
| 9 | let cache1: LRUCache<u64, u64> = LRUCache::new(10000, EvictStrategy::Immediate); |
| 10 | |
| 11 | let evict_strategy = |
| 12 | EvictStrategy::Probabilistic(ProbEviction::new(f16::from_f32_const(0.03125))); |
| 13 | let cache2: LRUCache<u64, u64> = LRUCache::new(10000, evict_strategy); |
| 14 | |
| 15 | let mut rng = rand::thread_rng(); |
| 16 | |
| 17 | group.bench_function("immediate eviction", |b| { |
| 18 | b.iter(|| { |
| 19 | let x = rng.gen_range(u64::MIN..u64::MAX); |
| 20 | cache1.get_or_insert(x, || Ok::<u64, Box<dyn std::error::Error>>(x)) |
| 21 | }) |
| 22 | }); |
| 23 | |
| 24 | group.bench_function("probabilistic eviction", |b| { |
| 25 | b.iter(|| { |
| 26 | let x = rng.gen_range(u64::MIN..u64::MAX); |
| 27 | cache2.get_or_insert(x, || Ok::<u64, Box<dyn std::error::Error>>(x)) |
| 28 | }) |
| 29 | }); |
| 30 | |
| 31 | group.finish(); |
| 32 | } |
| 33 | |
| 34 | criterion_group!(benches, criterion_benchmark); |
| 35 | criterion_main!(benches); |
nothing calls this directly
no test coverage detected