需要使用到的头文件:
#include <sys/time.h>
检测代码如下:
struct timeval tpstart,tpend;
gettimeofday(&tpstart,NULL);
QString ipStr = getIp(); //被测运行时间的函数
gettimeofday(&tpend,NULL);
int timeuse=(1000000*(tpend.tv_sec-tpstart.tv_sec) + tpend.tv_usec-tpstart.tv_usec);
printf("use time : %d us",timeuse);