比较两个函数花了多长时间

时间:2015-06-21 15:21:06

标签: c

我有两个功能,我想打印每个功能完成的时间。

到目前为止我所拥有的:

int main()
{
   clock_t tic1 = clock();
   shell_sort(array, 100000);
   clock_t toc1 = clock();
   printf("shellsort took: %f seconds\n", (double)(toc1 - tic1) / CLOCKS_PER_SEC);

   clock_t tic2 = clock();
   bubble_sort(array, 100000);
   clock_t toc2 = clock();
   printf("bubblesort took: %f seconds\n", (double)(toc2 - tic2) / CLOCKS_PER_SEC);

   return 0;
}

它应该工作正常,但在打印第一个功能的持续时间后它会停止。感觉程序仍在运行。没有“按任意键继续”。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

我认为您的排序功能很好。

您正在尝试检查冒泡排序以对100,000个值进行排序所需的时间。我想你知道它很慢。请耐心等待wait

enter image description here

正如您所看到的那样,您应该等待将近一分钟。

相关问题