Program description: The code's outer for loop iterates over different array sizes. For each array size, there is an inner for loop that iterates over different strides. For a given array size and stride, the code repeatedly walks through the array for 20 seconds. It subtracts out the loop overhead and then prints the latency per array element access.
Hint: As the array size increases, at some point it spills out of L1, L2, TLB, etc. For small strides, latency should be small since a block will have a miss (in some cases), followed by several hits. For these smaller strides, as the stride increases, the hits per miss reduces, thus increasing average latency. For larger strides, only some blocks in the array are brought to the cache, i.e., the effective working set reduces - this can help keep the working set cache resident, thus improving latency. The effect above also applies to the TLB so the final latency is affected by cache and TLB residency. For very large strides, the number of pages touched also reduces, further reducing latency per access.