Linux C 统计函数执行时间
代码实现
#include <stdio.h>
#include <time.h>
int main(void)
{
clock_t start, end;
double cpu_time_used;
start = clock();
/* function to be test here */
end = clock();
cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
printf("time: %fs\n", cpu_time_used);
return 0;
}
注意
该方法仅适用于串行执行的函数
参考
ChatGPT 3.5