Cache Hit Ratio Formula
The cache hit ratio formula measures cache effectiveness.
Learn how to calculate hit rate, miss rate, and effective memory access time with examples.
The Formula
The cache hit ratio measures how often requested data is found in the cache (fast memory) rather than having to be fetched from slower main memory. It is one of the most important metrics in computer architecture and system performance tuning.
Variables
| Symbol | Meaning | Unit |
|---|---|---|
| h | Cache hit ratio | 0 to 1 (or %) |
| Miss Rate | 1 − h (fraction of accesses that miss) | 0 to 1 |
| t_c | Cache access time (fast) | nanoseconds (ns) |
| t_m | Main memory access time (slow) | nanoseconds (ns) |
| EMAT | Effective Memory Access Time | nanoseconds (ns) |
Effective Memory Access Time (EMAT)
This gives the average time to access memory, considering both cache hits and misses. On a miss, the CPU first checks the cache (t_c), then goes to main memory (t_m), so the miss penalty is t_c + t_m.
Simplified (simultaneous lookup — some architectures):
Example 1
Cache hit ratio = 90%, cache time = 5 ns, main memory = 100 ns
EMAT = 0.90 × 5 + 0.10 × (5 + 100)
= 4.5 + 10.5
EMAT = 15 ns — 85% faster than always going to main memory (100 ns)
Example 2
Improving hit ratio from 90% to 99%: same cache/memory times
EMAT at 99% = 0.99 × 5 + 0.01 × 105 = 4.95 + 1.05
EMAT = 6.0 ns — 60% faster than 90% hit ratio (15 ns)
Multi-Level Cache (L1, L2, L3)
Modern CPUs have 3 levels of cache. Each level is checked in order — only on a miss does the CPU proceed to the next level:
- L1 cache: ~1–4 ns, typically 32–512 KB, hit rate ~85–95%
- L2 cache: ~4–12 ns, typically 256 KB–4 MB, hit rate ~90–99%
- L3 cache: ~20–50 ns, typically 8–64 MB, hit rate ~99%+
- Main RAM: ~60–100 ns
- SSD: ~100,000 ns (0.1 ms)
- HDD: ~10,000,000 ns (10 ms)
When to Use This Formula
- CPU architecture design and cache sizing decisions
- Database query cache performance analysis
- Web server caching (CDN hit ratio, reverse proxy cache)
- Redis / Memcached effectiveness measurement
- Operating system page cache evaluation