Zi 字媒體
2017-07-25T20:27:27+00:00
純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;
}
寫了
5860316篇文章,獲得
23313次喜歡