Re:Gallery of Processor Cache Effects
by joseraul on Sunday December 21, 2014 @09:57AM
(#8779866)
Most examples are classical cache effects, but the last one is such a puzzle.
How can incrementing 2 variables be slower than incrementing 4 variables?
[ Parent
| on HN ]
Perhaps the result is an average rather than the best result?
I wondered about this too so I tried it on my PC, though I had to make up my own timing code since the author doesn't say what he was doing. Results for me were more in line with what I'd expect, with both 4-variable cases being the same speed and the 2-variable one being a bit quicker. (All the data for the loop will fit into 2 or 3 cache lines so I don't think there's much chance you'll see any memory effects being measured.)
This is compiling for x64.
This feels like a Nagle-esque[1] issue (maybe delaying actions until a buffer fills, for example?)
[1] http://blogs.msdn.com/b/windowsazurestorage/archive/2010/06/...