Std :: chrono doesn't seem to give exact resolution / frequency

I read about it and the numbers don't add up. On my operating system (Windows), I can check the resolution of the system clock as follows:

LARGE_INTEGER largeInt; // Basically a struct/union containing a long long
QueryPerformanceFrequency(&largeInt);
// largeInt now holds the frequency of my system clock, it 3903987
// This ends up being a resolution of about 256 nanoseconds

Everything is fine, but now I want to use std :: chrono to check the same details. According to cppreference.com and the popular answer on this site, the std :: chrono clock period is a compilation time coefficient consisting of a numerator and a denominator that determines how many seconds are between ticks.

cppreference.com:

period: a std :: relation representing the tick period (i.e. the number of seconds per tick)

And from the answer:

The minimum representable duration is high_resolution_clock :: period :: num / high_resolution_clock :: period :: den seconds. You can print it like this:

std::cout <<
(double)std::chrono::high_resolution_clock::period::num /   
std::chrono::high_resolution_clock::period::den;

So I tried:

// On Windows the result is typedeffed as intmax_t, which is a typedef for a long long
    intmax_t numerator = std::chrono::high_resolution_clock::period::num;
    intmax_t denominator = std::chrono::high_resolution_clock::period::den;
    // numerator is 1 and denominator is one billion, which would suggest a 
    // tick period of one nanosecond?

, , ? OS, , . , , 3903987, , .

, / , high_resolution_clock:: is_steady . 3903994 3903991, , , , . , , .

, / std:: chrono?

0
1

period::num period::den , HPC.

. "" - , , .

" ", . - .

, 256 , high_resolution_clock::now(), , ( !).

++ . .

, clock::now() . , std-, high_performance_clock. , 100% , , steady_clock ( ).

, - time_t, . ( , , )

, , , time_t, , , .

- SO, .

, , . , , -- .

0

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


All Articles