作者allanyh (allan)
看板C_and_CPP
标题Re: [问题] unix下 c++程式 CLOCKS_PER_SEC 与CLK_ …
时间Thu Feb 12 07:49:19 2009
※ 引述《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