C語言計算程序中某一個函數或算法的執行時間

計算程序中某一個函數或算法的執行時間

#include <stdio.h>
#include <time.h>
#include <stdlib.h>

int main()
{
    long i = 10000000L;
    clock_t start, finish;
    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;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章