The loop that should be fast and is not

medium~20 min#c++#cache#memory#performance

Two functions sum the same N x N matrix stored in a row-major array. One iterates rows in the outer loop, the other iterates columns in the outer loop. For a large N the second is many times slower.

Why — and roughly how much slower would you expect, and why does it depend on N?

Solution — locked

Sign in to unlock this one

The solution opens once you explain the idea in your own words and it passes the grader — which needs an account to record. Signing in is free.

Log in