参考资料:粗糙的几种用法:
http://www.zhixing123.cn/net/29619.html
那如何获取高精度的CPU执行时间的?
其实很多CPU中都有一条获取系统时钟的指令,我们之所不用上面链接那种,这是因为计算相对来说还是比较粗糙一点的。
#include<stdio.h>
#include"rdtsc.h"//vs2013 无法打开包括文件: “rdtsc.h”: No such file or directory
int main(int argc, char*argv[])
{
unsigned long long start_time, end_time;
start_time = rdtsc();
//执行要测试的程序
for (int i = 0; i < 0x7fffffff; i++)
{
}
end_time = rdtsc();
printf("%llu\n",end_time-start_time);
return 0;
}
代码源自:http://blog.csdn.net/mazheng1989/article/details/7096859