Skip to content

Same loop, same numbers, 11x slower

Youtube 0:52 226 views
ZetBit

ZetBit

@UC3zY4m_LrHraxTCv-lFPPIg

I added up the same 16 million numbers twice with the same loop. In order it took 9 ms. In random order it took 96 ms. The CPU fetches memory in 64-byte blocks and prefetches the next one when you walk forward, so random reads end up waiting for main memory (about 90 ns per read in my test, versus about 1 ns from the closest cache).

#programming #performance #gamedev #shorts

More Videos