This directory contains the benchmark suite for CacheKit cache policies.
workloads.rs - Policy comparison across standard workloads
- Hit rate benchmarks for all policies × all workloads
- Scan resistance tests
- Adaptation speed tests
- Comprehensive benchmarks with latency/throughput
- Run:
cargo bench --bench workloads
ops.rs - Micro-operation benchmarks
- Individual get/insert operation latency
- Measures raw policy overhead
- Run:
cargo bench --bench ops
comparison.rs - External crate comparison
- Compares CacheKit policies against
lruandquick_cachecrates - Run:
cargo bench --bench comparison
policy/*.rs - Policy-specific benchmarks
- Unique operations for each policy
- Run:
cargo bench --bench policy_lru, etc.
reports.rs - Human-readable console reports
- Prints comparison tables for policies
- No Criterion overhead, just raw measurements
- Run:
cargo bench --bench reports -- <report_type> - Available reports:
hit_rate- Hit rate comparison tableextended- Extended workload comparisonscan- Scan resistance metricsadaptation- Adaptation speed metricsdetailed- Single benchmark deep divememory- Memory overhead comparisoncomprehensive- Full policy tablesall- Run all reports
runner.rs - JSON artifact generator
- Produces structured JSON results for automation
- Captures full environment metadata (git, rustc, CPU)
- Output:
target/benchmarks/<timestamp>/results.json - Run:
cargo bench --bench runner
common/ - Shared benchmark utilities
registry.rs- Central registry of policies and workloadsmetrics.rs- Benchmark measurement utilitiesworkload.rs- Workload generatorsjson_results.rs- JSON output schema
cargo bench --bench reports -- hit_ratecargo bench --bench runner
# Output: target/benchmarks/<timestamp>/results.jsoncargo bench --bench workloads# After running criterion benchmarks
open target/criterion/report/index.htmlDefault parameters (defined in each benchmark file):
- Capacity: 4,096 entries
- Universe: 16,384 possible keys
- Operations: 200,000 per benchmark
- Seed: 42 (for reproducibility)
All benchmarks use the central policy registry (common/registry.rs).
Current policies:
- LRU - Least Recently Used
- LRU-K - LRU with K-distance tracking
- LFU - Least Frequently Used
- Heap-LFU - LFU with heap-based eviction
- Clock - Clock/Second-Chance algorithm
- S3-FIFO - Simple Scalable FIFO variant
- 2Q - Two-Queue algorithm
To add a new policy:
- Add entry to
for_each_policy!macro incommon/registry.rs - All benchmarks automatically include it
Current standard workloads:
uniform- Uniform random accesshotset_90_10- 90% of accesses to 10% of keysscan- Sequential accesszipfian_1.0- Zipfian distribution (α=1.0)scrambled_zipf- Zipfian with hashed keyslatest- Recent keys are more popularscan_resistance- Mixed point queries and sequential scansflash_crowd- Sudden traffic spikes
Extended workloads include: zipfian_0.8, shifting_hotspot, exponential, pareto, correlated, loop_small, working_set_churn, bursty, mixture.
To add a new workload:
- Add entry to
STANDARD_WORKLOADSorEXTENDED_WORKLOADSincommon/registry.rs - All benchmarks automatically test it
- HTML reports in
target/criterion/ - Statistical analysis with confidence intervals
- Automatic regression detection
- Plain text tables
- Hit rate percentages
- Throughput (ops/sec)
- Latency distribution (p50, p95, p99)
- Structured data in
target/benchmarks/<timestamp>/results.json - Includes metadata (git commit, rustc version, CPU model)
- Schema version 1.0.0
- ~60KB per run, 91 results
- Use release builds:
cargo bench - Close other applications to reduce noise
- Run multiple times and check consistency
- Use Criterion for statistical rigor
- Use
reports.rsfor quick comparisons - Check
hit_ratefirst to catch regressions - Use
runner.rsfor CI/CD integration
- Run full benchmark suite:
cargo bench - Generate JSON artifact:
cargo bench --bench runner - Compare with previous releases
- Document significant changes in CHANGELOG
- Reduce
OPSconstant in benchmark file - Run specific workloads:
cargo bench --bench workloads -- uniform - Use
reports.rsinstead of Criterion
- Ensure system is idle during benchmarking
- Disable CPU frequency scaling if possible
- Run on dedicated hardware for consistent results
- Use longer warmup periods
- Check
for_each_policy!macro syntax - Verify policy implements
Cache<K, V>trait - Ensure type parameters match (some policies use
Arc<V>, others useV)