------解决方案--------------------
clock_gettime可获得纳秒级精确
linux rdtsc 纳秒级计时
2011-06-30 21:30:19
分类: LINUX
- 部分代码
-
- unsigned int ts,te;
- unsigned int sdx,edx;
- unsigned long long int clock_cycles;
- unsigned int max=1<<31;
- unsigned long long int max0=(unsigned long long int )max*2;
-
- __asm__ __volatile__(
- "rdtsc\n\t"
- :"=a"(ts),"=d"(sdx));
-
- //-------------some functions need to record time-----------//
- b
-
- __asm__ __volatile__(
- "rdtsc\n\t"
- :"=a"(te),"=d"(edx));
-
-
- printf("tick ax start =%u tick end=%u \n",ts, te);
- printf("tick dx start =%u tick end=%u \n",sdx, edx);
- clock_cycles=(unsigned long long)(edx-sdx)*max0 te-ts;
- //or clock_cycles=(unsigned long long)(edx-sdx)*0x0100000000l+ te-ts;
- printf("ticks=%llu\n",clock_cycles);