I want to study the effect of the cache size on code. For programs operating on large arrays, there can be a significant speed-up if the array fits in the cache.
How can I meassure this?
I tried to run this c program:
#define ARRAYSIZE 200000
#define ITERATIONS 5000
int ray[ARRAYSIZE];
int sum;
main() {
int iter, i;
clock_t time1, time2;
int time;
time1 = clock();
for (iter=0; iter<ITERATIONS; iter++)
for (i=0; i<ARRAYSIZE; i++)
sum += ray[i];
time2 = clock();
time = (time2 - time1) * 1000 / CLK_TCK;
printf ("CPU time: %i millisecondsn", time);
}
taking values of ARRAYSIZE and ITERATIONS (keeping the product, and hence the number of instructions, constant) in order to check if the program run faster if the array fits in the cache, but I always get the same CPU time.
Can anyone say what I am doing wrong?
