linux下测试C程序代码运行时间的方法:
#include <stdio.h> #include <sys/time.h> #include <unistd.h> int main() { struct timeval tpstart,tpend; float timeuse; gettimeofday(&tpstart,NULL); for(int i=0;i<10;i++) { usleep(200000);//暂停200ms } gettimeofday(&tpend,NULL); timeuse=1000000*(tpend.tv_sec-tpstart.tv_sec)+tpend.tv_usec-tpstart.tv_usec; timeuse/=1000000; printf("Used Time:%f\n",timeuse); return 0; }
http://www.cnblogs.com/eavn/archive/2010/08/29/1811878.html