Cache doesn't seem to be effective

48 views Asked by At

I want to test the role of Cache? I found that Cache didn't seem to be effective.

unsigned time1, time2;
int num=1;
int junk=0;
_mm_clflush(&num);
time1 = __rdtscp((unsigned int*)&junk);
num=2;
time2 = __rdtscp((unsigned int*)&junk) ;
printf("%u\n",(time2-time1));

The output of this code is 59.

unsigned time1, time2;
int num=1;
int junk=0;
//_mm_clflush(&num);
num=3;
time1 = __rdtscp((unsigned int*)&junk);
num=2;
time2 = __rdtscp((unsigned int*)&junk) ;
printf("%u\n",(time2-time1));

The output of this code is also 59. The num variable in the first code is not in the cache, but the second is in the cache. Why is the time the same?

0

There are 0 answers