使用clock_gettime
C++ 中可以使用clock_gettime, 得到
clock_gettime(CLOCK_REALTIME, &time1); ... your code to profile ... clock_gettime(CLOCK_REALTIME, &time2);
使用rdtscp
如果想得到更高精度的计时, 比如以CPU的时钟周期为单位, 对于比较新的Intel CPU, 可以使用rdtscp指令来获得当前CPU时钟周期读数.比较前后两次读数就可以得到以时钟周期为单位的逝去时间.
// rdtscp ensure serialization, supported by newer CPUs static __inline__ uint64_t rdtscp(void) { uint32_t hi, lo; __asm__ __volatile__ ("rdtscp" : "=a"(lo), "=d"(hi)); return ((uint64_t)lo | ((uint64_t)hi << 32); }
1 comment:
jordan 6
kyrie 6 shoes
paul george
jordan shoes
yeezy
off white nike
yeezy 700
lebron shoes
supreme clothing
kd 10
Post a Comment