computers/cpu-cache-why-reading-a-grid-by-rows-beats-columns-step-by-step.md

CPU cache: why reading a grid by rows beats columns, step by step

Computers · 5 min read ·

Two loops add up the same grid of numbers, yet one can run about ten times slower. The reason is a small, fast memory inside your processor called a cache.

Step through a tiny cache yourself: walk a grid row by row, then column by column, and watch hits turn into misses. Then see the same effect in a real C program.

A grid of 64 squares with one column highlighted orange, showing a column walk where every read misses the cache

$ ls computers/

see all →