Theoretically the second should be faster. Also, I think this might be a little faster than the first example you gave.
long foo=0;long bar=0;long array[10000][5]= {3,6,2,6,8};for (bar=0; bar<=5; bar++) { for (foo=0; foo<=9999; foo++) { array[foo][bar]++; }}
All I did was switch the inner and outer loops. Putting the loop with more iterations as the inner loop should be faster, I think. Also it might be possible to write it quite a bit faster using pointers rather than indexes into a 2D array. Maybe like this.
long array[10000][5]= {3,6,2,6,8};long * p, * end = array + 49999;for (p=array; p != end; p++) (*p)++;}
[edited by - Russell on April 2, 2003 6:00:16 PM]