我要测试Cache的角色吗?我发现Cache似乎无效。
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));
此代码的输出为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));
此代码的输出也是59。 第一个代码中的num变量不在缓存中,而第二个代码在缓存中。为什么时间一样?