看板 C_and_CPP 關於我們 聯絡資訊
※ 引述《WalkingIce ( 殺手哥吉拉 13)》之銘言: : ※ 引述《allanyh (allan)》之銘言: : : 請教各位版友: : : 我在 unix下執行c++程式 : : void main() : : { : : clock_t start, finish; : : double duration1,duration2; : : start = clock(); : : ... : : ... : : finish = clock(); : : duration1 = (double)(finish - start) / CLOCKS_PER_SEC; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 感謝W兄的解答,再請教 如果 CLOCKS_PER_SEC=1000000, 那上面這一行會是相當把clock數換算成於秒數嗎?? 非常感謝 : : duration2 = (double)(finish - start) / CLK_TCK; : : printf("duration1:[%3f], duration2:[%3f]\n",duration1,duration2); : : } : : 跑出來結果會不同?? duration1:[0.01], duration2:[100],差了快10^4了 : : 請問CLOCKS_PER_SEC跟CLK_TCK差別在哪?? : 看看 header 檔就知道了。(or "man 3 clock") : /usr/include/bits/time.h : CLK_TCK 這個數字是 100,它來自於 sysconf(2) : clock ticks - _SC_CLK_TCK : The number of clock ticks per second. The corresponding variable : is obsolete. It was of course called CLK_TCK. (Note: the macro : CLOCKS_PER_SEC does not give information: it must equal 1000000.) -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.169.234.225