double duration; printf( "Time to do %ld empty loops is ", i) ; start = clock(); while( i-- ); finish = clock(); duration = (double)(finish - start) / CLOCKS_PER_SEC; printf( "%f seconds\n", duration ); return 0; } 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12....
我一开始用的clock()函数,但是精度不够,gpt告诉我改成这样,但是这样直接无法编译运行#include <stdio.h>#include <stdlib.h>#include// 冒泡排序void bubbleSort(int array[], int size){for (int i = 0; i < size - 1; i++){for (int
C语言中用clock()函数来测量函数(算法例程)运行时间 #include<stdio.h>#include<stdlib.h>#includeusing namespacestd;intmain(){clock_tstart_time, end_time;doubleduration; start=clock();//开始计时刻for(inti =0; i <10000; i++) { func();// 这里是要执行的函数} finish=clock();//终止计时...