A loop reuses the same few variables thousands of times. Which kind of locality is that?

Temporal locality: reusing the same data soon after.

Start playing free

  1. Temporal locality ✔
  2. Spatial locality
  3. Sequential locality

Why: Temporal locality means using the same data again soon, so it is still in cache. Spatial locality means using data stored next to what you just used, like walking through an array. Code with good locality gets far more cache hits.

Huh, didn't know that: The instructions in a loop body show temporal locality too, because the same instructions run every pass.

The dad joke
Why does temporal locality love reruns? It always wants to see the same thing again.
Like this card?
Play the game

References

Answer: Temporal locality. Temporal locality means using the same data again soon, so it is still in cache. Spatial locality means using data stored next to what you just used, like walking through an array. Code with good locality gets far more cache hits.

  1. OpenStax Introduction to Computer Science 5.5: Memory Hierarchy openstax.org/books/introduction-computer-science/pages/5-5-memory-hierarchy
    if we reuse the data as much as possible, we get better performance because the data is available in the cache
    Checked 2026-10-10.

Think this answer is wrong? Tap "Challenge this answer" on the card in the game and tell us why.

Test yourself in the game