作者allanyh (allan)
看板C_and_CPP
标题Re: [问题] unix下 c++程式 CLOCKS_PER_SEC 与CLK_ …
时间Sat Feb 14 14:40:22 2009
※ 引述《WalkingIce ( 杀手哥吉拉 13)》之铭言:
: ※ 引述《allanyh (allan)》之铭言:
: : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
: : 感谢W兄的解答,再请教 如果 CLOCKS_PER_SEC=1000000,
: : 那上面这一行会是相当把clock数换算成於秒数吗??
: : 非常感谢
: 就像这一段的解释, CLOCKS_PER_SEC 没有给你甚麽讯息。
: 你要除以 CLK_TCK 就会得到秒数了
不好意思,这样我又有点迷糊了,因为我的程式不可能跑100秒啊,不到一秒钟就run出来了
到底哪个才是把clock换算成秒数
void main()
{
clock_t start, finish;
double duration1,duration2;
start = clock();
...
...
finish = clock();
duration1 = (double)(finish - start) / CLOCKS_PER_SEC;
duration2 = (double)(finish - start) / CLK_TCK;
printf("duration1:[%3f], duration2:[%3f]\n",duration1,duration2);
}
跑出来结果会不同?? duration1:[0.01], duration2:[100],差了快10^4了
我的机器上time.h的 CLOCKS_PER_SEC跟CLK_TCK为
#define CLOCKS_PER_SEC 1000000
#ifndef CLK_TCK
extern long _sysconf(int); /* System Private interface to sysconf() */
#define CLK_TCK ((clock_t) _sysconf(3)) /* clock ticks per second */
/* 3 is _SC_CLK_TCK */
#endif
可以帮我解答这个问题吗?非常感谢!!!
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.169.235.55