How can adding code to a loop make it faster?
My guess is, that in the first case two different branches end up in the same branch-prediction slot on the CPU. If these two branches predict different each time the code will slow down. In the second loop, the added code may just be enough to move one of the branches to a different branch … Read more