1.
#include<stdio.h>
#include<unistd.h> //sleep
unsigned long rpcc()
{
unsigned long result;
unsigned hi,lo;
asm volatile("rdtsc":"=a"(lo),"=d"(hi));
result = ((unsigned long long)lo)|(((unsigned long long)hi)<<32);
return result;
}
int main()
{
unsigned long start ,end;
start = rpcc();
sleep(2);
end = rpcc();
printf("time = %ld\n",end - start);
}
------------------------------------------------------------------------------------
2.
for (int i = start; i < end -10; i+=32)
{
//unsigned long long t1, t2;
volatile unsigned long long t1 = __rdtsc();
code;
volatile unsigned long long t2 = __rdtsc();
if(i == 32) cout << t2 - t1<< endl;
---------------------------------------------------------------------------------------