我正在使用 clock(),我想知道它是否会重置或达到最大值。我使用它的目的只是太受制于之前的函数调用并找出不同之处。
感谢到目前为止的帮助,但我真的无法让 chrono 的东西在 VS '12 中工作,但它很好,因为我认为它比我需要的多一点,我正在考虑使用 的时间( ) 但我不知道如何将 t_time 转换为仅包含当前秒数 0-60 的 int,有什么帮助吗?
最佳答案
就标准而言,
The range and precision of times representable in
clock_t
andtime_t
are implementation-defined.
(C99,§7.23.1 ¶4)
因此无法保证范围; clock()
的定义并没有说任何关于回绕的内容,尽管它说了
If the processor time used is not available or its value cannot be represented, the function returns the value
(clock_t)(-1)
所以我们可能会说超出clock_t
的范围可能会被看成是“它的值无法表示”;另一方面,这种解释意味着,一段时间后,clock()
变得完全无用。
事实上,如果我们深入到具体的实现 (glibc),我们会看到:
matteo@teokubuntu:~$ man 3 clock
Note that the time can wrap around. On a 32-bit system where CLOCKS_PER_SEC equals 1000000 this function will return the same value approximately every 72 minutes.
关于c++ - clock() 对于定时器来说可靠吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17118231/