sysconf(_SC_CLK_TCK)与CLOCKS_PER_SEC [英] sysconf(_SC_CLK_TCK) vs. CLOCKS_PER_SEC
问题描述
我想知道上述常量的返回值之间有什么区别.
I was wondering what is the difference between the return value of the aforementioned constants.
sysconf(_SC_CLK_TCK)返回100
CLOCKS_PER_SEC返回1,000,000
sysconf(_SC_CLK_TCK) returns 100
CLOCKS_PER_SEC returns 1,000,000
所以,假设我有这个:
...
start = clock();
// Process starts here
/* does something */
// Process ends here
end = clock();
double time = ((double) end-start)/CLOCK_PER_SEC; // this would return in seconds
...
如何计算流程使用的滴答数而不是时间?我是否将时间用于sysconf(_SC_CLK_TCK)或CLOCK_PER_SEC?
How do I calculate the amount of ticks used by the process, instead of the time? Do I use time used against sysconf(_SC_CLK_TCK) or CLOCK_PER_SEC?
我正试图了解它们的用法.
I am trying to understand the usage of those.
推荐答案
根据文档, clock()
返回的时间分辨率为 CLOCKS_PER_SEC
.
As per the documentation, clock()
returns time in resolution of CLOCKS_PER_SEC
.
其他时间函数返回的精度为 tick 的值. sysconf(_SC_CLK_TCK)
提供每秒的滴答数.这样的时间函数之一就是 times()
.
Other time functions return values with resolution in ticks. sysconf(_SC_CLK_TCK)
provides the number of ticks per second. One such time function is times()
.
这篇关于sysconf(_SC_CLK_TCK)与CLOCKS_PER_SEC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!