I’ve tried search without really finding an answer to this question that meets me requirements or explains it clearly enough.
I’m looking for a function or a way to implement a function that can retrieve the number of ticks or milliseconds in the same way that the timeGetTime() function does in windows.
I’m looking for a solution that only uses standard C++, no additional libraries or platform specifics (like timeGetTime() on windows or a linux equivalent; a multi-platform solution).
I’m trying to keep my code platform independent at the lower level of the library and I just want to know if anyone can tell me/point me to the way to put something together similar to timeGetTime().
Thanks
Update: I’m not necessarily looking for high performance and accuracy, I only need millisecond precision to see how much time has elapsed since I last checked.
You can use the ever so verbose
<chrono>library added in C++11.It has different types of clocks depending on what you want, with
system_clockbeing the only one that can be used withtime_tandhigh_resolution_clockbeing the one with the smallest tick possible.Timing things is relatively simple with it, for example: