MCPcopy Create free account
hub / github.com/cosdata/cosdata / criterion_benchmark

Function criterion_benchmark

tests/benches/lru_cache_benchmark.rs:6–32  ·  view source on GitHub ↗
(c: &mut Criterion)

Source from the content-addressed store, hash-verified

4use rand::Rng;
5
6fn 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
34criterion_group!(benches, criterion_benchmark);
35criterion_main!(benches);

Callers

nothing calls this directly

Calls 2

iterMethod · 0.45
get_or_insertMethod · 0.45

Tested by

no test coverage detected