需要统计一下程序运行的时间,在网上找了找,自己做了一个范例,还不错。代码如下:
#include <iostream>
#include <unistd.h>
#include <sys/time.h>
int main()
{
struct timeval tpstart,tpend;
double timeuse;
gettimeofday(&tpstart,NULL);
char strCommand[255];
for(int i=0; i<100000; i++)
gettimeofday(&tpend,NULL);
timeuse=1000000 * (tpend.tv_sec-tpstart.tv_sec) + tpend.tv_usec-tpstart.tv_usec;
timeuse/=1000000;
printf("process time is %lf s./n",timeuse);
return 0;
}