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

posted @ 2013-09-12 17:22  星语160523  阅读(1194)  评论(0编辑  收藏  举报