2
可能重复:
Why does the order of the loops affect performance when iterating over a 2D array?为什么更改循环迭代顺序会增加运行时间?
我有这个简单的for循环
for (i=0;i<10000;i++){
for(j=0;j<10000;j++){
a[i][j]=i+j;
}}
当我改变这些顺序的for循环来:
for (j=0;j<10000;j++){
for(i=0;i<10000;i++){
a[i][j]=i+j;
}}
我看到运行时显着增加。为什么会发生?
谢谢