Linux下C++程序获取运行时间的一种方式

struct timeval sTime, eTime;
gettimeofday(&sTime, NULL);
……
gettimeofday(&eTime, NULL);
long exeTime = (eTime.tv_sec-sTime.tv_sec)*1000000+(eTime.tv_usec-sTime.tv_usec); //exeTime 单位是微秒

 在linux下需要include头文件 #include <sys/time.h>

原文地址:https://www.cnblogs.com/james6176/p/3054075.html