C ++ chrono unexpected behavior

std::chrono::system_clock::time_point start;
//1 second passes
std::cout << (std::chrono::high_resolution_clock::now()-start).count();

The above code after 1 second in Visual Studio 2012 gives me 10000000, but in gcc 4.8.2 gives me 100000000.

Changing the last line to std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now()-start).count();works as expected and gives me the same result for both compilers.

How is this possible?

+4
source share
1 answer

According to http://en.cppreference.com/w/cpp/chrono/high_resolution_clock

The std :: chrono :: high_resolution_clock class represents the clock with the shortest tick period provided by the implementation.

So GCC has a different VS resolution.

The standard allows this, because different systems have different requirements for time accuracy.

, .

+4

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


All Articles