/* ** $Id: loop.c 819 2008-03-09 17:41:59Z phf $ ** ** Example for performance impact of memory access ** patterns. */ enum { SIZE=2048 }; double A[SIZE][SIZE]; int main(void) { for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { // first time(1) with this version, then comment this // one, uncomment the other, time(1) again; since the // memory access pattern is different, performance is // different (on all machines I know anyway)... A[i][j] = 1.0; //A[j][i] = 1.0; } } }