我实际上正在做一个程序来测试不同的排序算法。然而,当我尝试计时代码执行时,它只打印了3位小数,正如你在我粘贴的输出部分所看到的,我不知道为什么。
x1月0n1x日
//insertion sort test
time_t t = 0;
t = clock();
insertion(arr, n);
t = clock() - t;
double time_taken = ((double)t)/CLOCKS_PER_SEC; // in secondi
printf("insertion() took %f seconds to execute\n", time_taken);
fprintf(fp, "%f,", time_taken);
fflush(fp);
data.csv
0.001000,0.000000,0.000000,0.001000,0.000000
0.002000,0.000000,0.000000,0.002000,0.000000
0.005000,0.000000,0.000000,0.005000,0.000000
0.008000,0.001000,0.000000,0.008000,0.000000
0.004000,0.000000,0.000000,0.021000,0.000000
0.011000,0.000000,0.000000,0.024000,0.001000
0.008000,0.016000,0.000000,0.025000,0.000000
0.031000,0.001000,0.001000,0.029000,0.000000
0.041000,0.001000,0.000000,0.033000,0.000000
0.060000,0.001000,0.001000,0.051000,0.001000
0.062000,0.001000,0.000000,0.059000,0.001000
0.074000,0.002000,0.001000,0.068000,0.000000
0.085000,0.002000,0.001000,0.080000,0.000000
我用的是Windows11,AMD锐龙5处理器。可能是因为硬件或操作系统的一些配置。
1条答案
按热度按时间vh0rcniy1#
尝试运行以下命令:
如果CLOCKS_PER_SEC显示为1000,则这解释了精度限制为3个小数位的原因。