CLOCKS_PER_SEC Behavior on Different Operating Systems

I ran the cpp code, but I noticed that in Windows 7 CLOCKS_PER_SEC in code in C ++ gives 1000, and on linux fedora 16 it gives 1,000,000. Can anyone justify this behavior?

+6
source share
2 answers

What to justify? CLOCKS_PER_SEC defined as an implementation, and can be anything. All this indicates that the units returned by the clock() function. It does not even indicate clock() resolution: Posix requires 1,000,000, regardless of the actual resolution. If Windows returns 1000, that is probably not the actual resolution or. (I find that my Linux block has a resolution of 10 ms and my Windows has a resolution of 15 ms.)

+4
source

Basically, the implementation of the clock() function has some freedom of action for different operating systems. On Linux, Fedora watches are faster. It extinguishes 1 million times per second.

This clock signal is different from the clock frequency of your processor, at a different level of abstraction. Windows is trying to make the number of clock cycles equal to the number of milliseconds .

This macro expands to an expression representing the number of hours ticking in a second as the clock function returns.

Dividing the clock count by this expression gives the number of seconds.

CLK_TCK is the deprecated alias of this macro.

Link: http://www.cplusplus.com/reference/clibrary/ctime/CLOCKS_PER_SEC/

You should also be aware that the Windows implementation is not intended for real -time applications . A time of 1000 ticks is obtained by dividing the hardware clock by a power of 2. This means that they actually receive a clock pulse of 1024 ha. To convert it to a tick of 1000 ticks, Windows will skip some ticks, which means that some ticks are slower than others!

Separate hardware clocks (not processor clocks) are typically used for synchronization. Link: http://en.wikipedia.org/wiki/Real-time_clock

+2
source

Source: https://habr.com/ru/post/924425/


All Articles