Chapter 02 — Cache-Hierarchy Latency Probe
A random pointer-chase benchmark across five working-set sizes shows that memory-access cost tracks the cache hierarchy, not anything that looks like contention.
The full source for this example lives in
examples/concurrency/02-machine-underneath/— clone the repo,cdin, and./demo.sh.
Chapter reference: Doc 02 — The Machine Underneath
What it shows
A single-threaded benchmark builds a random single-cycle permutation over cache-line-sized nodes and times one link of the chase at five working-set sizes stepping from L1 up through DRAM. The permutation is random, not sequential, specifically so a hardware prefetcher has nothing to predict and the measurement stays a latency number rather than a bandwidth one. The hard assertion is ordering, not an absolute figure: latency must be monotonically non-decreasing as the working set grows past each cache level, since a bigger footprint can only match or lose to a smaller one. Exact nanosecond values and the DRAM/L1 ratio are reported for context, not asserted, since they depend on the host’s real cache sizes.
Running it
cd examples/concurrency/02-machine-underneath
./demo.sh # build + run cache_latency + verify.lua
./demo.sh --clean # remove the image