Home » Community » U++ community news and announcements » usecs
Re: usecs [message #50699 is a reply to message #50698] |
Thu, 06 December 2018 20:19   |
Zbych
Messages: 327 Registered: July 2009
|
Senior Member |
|
|
mirek wrote on Thu, 06 December 2018 19:46A the moment, it seemed like a good solution to use what C++ lib provides.
I strongly disagree. I've made a test and std::chrono::high_resolution_clock::is_steady returned false in Linux/Gcc.
That means that new version of msecs is not reliable. Maybe for usecs it doesn't matter, but msecs is used to measure timeouts in many places in Upp.
My proposition is to use steady_clock for msecs instead:
int msecs(int prev)
{
auto p2 = std::chrono::steady_clock::now();
return (int)std::chrono::duration_cast<std::chrono::milliseconds>(p2.time_since_epoch()).count() - prev;
}
I compared returned value with old implementation (clock_gettime(CLOCK_MONOTONIC...) and they are exactly the same.
Resolution of steady_clock in Linux is about 1ms, so it doesn't make sense to use it in usecs.
[Updated on: Thu, 06 December 2018 20:35] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Sat May 10 05:03:05 CEST 2025
Total time taken to generate the page: 0.03112 seconds
|