I did two test about java loop as below. First test with int int w = q[i][j]; the TotalTime is about 5ms. Second test without int w = q[i][j]; The TotalTime is about 40ms. I do not understand that remove one line code, but use much more time. Why?
Test1:
int[][] p = new int[10000][10000];
int[][] q = new int[10000][10000];
long startTime = System.currentTimeMillis();
for(int i = 0; i<10000; i++){
for(int j = 0; j<10000; j++){
int k = p[i][j];
int w = q[i][j];
}
}
long endTime = System.currentTimeMillis();
long TotalTime = endTime - startTime;
System.out.println(TotalTime); //It is about 5
Test2:
int[][] p = new int[10000][10000];
int[][] q = new int[10000][10000];
long startTime = System.currentTimeMillis();
for(int i = 0; i<10000; i++){
for(int j = 0; j<10000; j++){
int k = p[i][j];
// int w = q[i][j];
}
}
long endTime = System.currentTimeMillis();
long TotalTime = endTime - startTime;
System.out.println(TotalTime); //it is about 40