Is there a standard equivalent to the timeGetTime () library?

I tried the search without finding an answer to this question that meets my requirements or explains it clearly enough.

I am looking for a function or a way to implement a function that can get the number of ticks or milliseconds in the same way as the timeGetTime () function on Windows.

I'm looking for a solution that uses only standard C ++, no additional libraries or platform specifications (e.g. timeGetTime () on Windows or the Linux equivalent, multi-platform solution).

I try to keep my code platform independent at a lower level of the library, and I just want to know if someone can tell me / tell me the way to map something along with timeGetTime ().

thanks

Update: I'm not necessarily looking for high performance and accuracy, I only need millisecond accuracy to find out how much time has passed since the last check.

0
source share
2 answers

You can use the ubiquitous <chrono> library added in C ++ 11.

It has different types of clocks depending on what you want, with system_clock being the only one that can be used with time_t and high_resolution_clock , which can be the smallest.

Temporary things are relatively simple with it, for example:

 #include <iostream> #include <chrono> int main() { auto now = std::chrono::high_resolution_clock::now(); //do stuff here auto then = std::chrono::high_resolution_clock::now(); std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(then-now).count(); } 
+1
source

C ++ 11 added the <chrono> header, which provides a standardized way to read system time with a higher resolution than the old localtime . However, accuracy is platform dependent.

The steady_clock class steady_clock probably be most useful to you.

+3
source

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


All Articles