1 /* 2 clock():捕捉从程序开始运行到 clock() 被调用时所耗费的时间,时间单位 3 是clock tick, 即:“时钟打点”。 4 5 常数CLK_TCK:机器时钟每秒所走的时钟打点数。 6 */ 7 8 #include <stdio.h> 9 #include <time.h> 10 11 clock_t start, stop; 12 // clock_t 是 clock() 函数返回的变量类型 13 double duration; 14 // 纪录被测函数运行的时间, 单位为秒 15 16 int main() 17 { 18 // 不在测试范围内的准备工作写在 colck() 调用之前 19 start = clock(); 20 my_function(); 21 stop = clock(); 22 // 其他不在测试范围的处理写后面,例如下面的输出语句 23 duration = ((double)(stop - start))/CLK_TCK; 24 25 return 0; 26 27 }
时间: 2024-12-05 06:22:59