Linux 下C语言测量程序运行的时间

添加头文件

#include <sys/time.h>

测量方法

struct timeval StartTime;
struct timeval EndTime;
double TimeUse=0;

gettimeofday(&StartTime, NULL);  //测量开始
 
//要测量的程序代码
 
gettimeofday(&EndTime, NULL);   //测量结束

TimeUse = 1000000*(EndTime.tv_sec-StartTime.tv_sec)+EndTime.tv_usec-StartTime.tv_usec;
TimeUse/=1000;  //测量结果,毫秒级别
原文地址:https://www.cnblogs.com/xingboy/p/14517760.html