最近一直在比程式的執行速度,測的方法又五花八門@@
這邊就記一個用time.h中的函式來計算所花時間的辦法:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
clock_t start, end;
// Start Record the time
start = clock();
// Your program....
// Record the end time
end = clock();
double diff = end - start; // ms
printf(" %f ms" , diff);
printf(" %f sec", diff / CLOCKS_PER_SEC );
return 0;
}