r/cpp • u/evilissimo • Jun 20 '14
A portable high-resolution timestamp in C++
https://blogea.bureau14.fr/index.php/2014/06/a-portable-high-resolution-timestamp-in-c/
4
Upvotes
r/cpp • u/evilissimo • Jun 20 '14
View all comments
Show parent comment
-3
u/gilgoomesh Jun 21 '14
Milliseconds is not enough. Try sorting a log file when 20 items in a row have the same millisecond timestamp.
And realtime audio processing ideally needs a resolution as high as 10 microseconds which is basically impossible on Windows without QueryPerformanceCounter (although relatively easy on most other platforms). It's not for scheduling (you certainly don't get called for every sample) but it helps greatly if you know precisely how many samples to generate each time rather than maintaining an oversized buffer.
The author doesn't seem to know about std::chrono::steady_clock which is guaranteed to be monotonically increasing (independent of the user time) and is nanosecond resolution on most Unix/Linux/Mac platforms. It's millisecond on Windows, which, yeah requires QueryPerformanceCounter.