gpt4 book ai didi

c - sysconf(_SC_CLK_TCK) 与 CLOCKS_PER_SEC

转载 作者:太空狗 更新时间:2023-10-29 11:12:38 25 4
gpt4 key购买 nike

我想知道上述常量的返回值有什么区别。

sysconf(_SC_CLK_TCK) 返回 100
CLOCKS_PER_SEC 返回 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 的时间?

我正在尝试了解它们的用法。

最佳答案

根据文档,clock() 返回分辨率为 CLOCKS_PER_SEC 的时间。

其他时间函数返回分辨率为 的值。 sysconf(_SC_CLK_TCK) 提供每秒滴答数。 times() 就是这样一种时间函数。

关于c - sysconf(_SC_CLK_TCK) 与 CLOCKS_PER_SEC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39712808/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com