The default way of using for loops which is taught in most cases looks something like this:
for (int x = 0; x < 32; x++)
{
for (int y = 0; y < 32; y++)
{
level[x][y].update();
}
}
But some people insist that swapping the x and y order in the for loop increases performance. I suspect that this is because of cache misses?
for (int y = 0; y < 32; y++)
{
for (int x = 0; x < 32; x++)
{
level[x][y].update();
}
}
Can anybody explain if this is correct and if so, WHY does it help? If not, what is the reason?