180 Introduction to Concurrency in Programming Languages
previous iteration, thus requiring a costly request to main memory. The per-
iteration time will be very high, leading to a slow algorithm. On the other
hand, simply swapping the loops will result in the identical output (in this
case), but consecutive accesses will be contiguous in memory, allowing the
slow main memory accesses to be absorbed by the higher performing cache
accesses, resulting in an overall performance improvement.
We show this example of single threaded memory performance and caching
issues to illustrate the concept that the underlying hardware can have effects
on the performance of program code without impacting its correctness. Un-
derstanding this simple case with a single ...