Why Is 1 Loop So Much Slower Than 2 Loops

A really interesting in-depth question was posted over at stackoverflow.com asking why 1 loop seems to be so much slower than 2 loops. The discussion on the page goes into great and interesting detail on what’s going on behind the scenes and why there is such a decrease in speed between 1 and 2+ loops. Interestingly, it seems that the answer has something to do with the CPU cache and the way it handles the memory.

Why is one loop so much slower than two loops? (stackoverflow.com)

Written on December 20, 2011