I came across this great youtube tutorial and in one of the slides I saw something I didn't understand. Why is this happening? Is this compiler related?
Version #1 looks like this:
const int N = 5000;
float a [N*N];
for (int x=0; x<n; ++x)
for(int y=0; y<N; ++y)
sum+=a[x+y*N];
and takes about 239.4ms to execute.
And version #2 looks like this:
const int N = 5000;
float a [N*N];
for (int y=0; y<n; ++y)
for(int x=0; x<N; ++x)
sum+=a[x+y*N];
and takes about 79.5ms to execute. Why is this happening?