純C/C++ clock()函數

純C/C++ clock()函數

純C/C++ clock()函數


資料來源: http://www.cplusplus.com/reference/ctime/clock/

http://puremonkey2010.blogspot.com/2010/08/c-cc.html


線上編譯器: https://www.tutorialspoint.com/compile_c_online.php

code(計算時間差):

#include "stdio.h"   
#include "stdlib.h"   
#include "time.h"   

int main( void )   
{   
    long     i = 10000000L;   
    clock_t start, finish; //typedef long clock_t;   
    double   duration;   
    /* 測量一個事件持續的時間*/   
    printf( "Time to do %ld empty loops is \n", i );   
    start = clock();   
    while( i-- )       ;   
    finish = clock();   
    duration = (double)(finish - start) / CLOCKS_PER_SEC;
	printf( "%f seconds\n", duration );   
	printf ("It took me %d clicks (%f seconds).\n",(finish - start),(double)(finish - start)/CLOCKS_PER_SEC);
	return 0;
} 

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *