其实就是工程上要一直测试时间,找了很多,觉得下面这个计算时间的方法还不错,就总结一下,还是很方便的。
#include<sys/time.h>using namespace std;structtimevalt_start,t_end;longcost_time=0;longstart,end;//开始计时gettimeofday(&t_start,NULL);start=((long)t_start.tv_sec)*1000+(long)t_start.tv_usec/1000;////需计时程序////结束计时,并输出代码运行损耗时间gettimeofday(&t_end,NULL);end=((long)t_end.tv_sec)*1000+(long)t_end.tv_usec/1000;cost_time=end-start;std::cout<<"the programme Cost time: "<<cost_time/float(1.0)<<" ms"<<std::endl;加油加油加油!疯狂给自己?!