I'd like to get the current number of nanoseconds since midnight, with the lowest latency.
My platform is Linux/Centos 7 with Clang. I do not care about portability.
I found this <chrono>
struct,
but they are dividing by seconds/milliseconds etc to get the result.
I also found this which could be modified for nanoseconds:
struct timeval tv;
int msec = -1;
if (gettimeofday(&tv, NULL) == 0)
{
msec = ((tv.tv_sec % 86400) * 1000 + tv.tv_usec / 1000);
}
https://stackoverflow.com/a/10499119/997112
but again they are using a division. Is there anything quicker, avoiding modulus and divisions?
I would assume the fastest way would be:
- Get the time now
- Multiple number of hours, minutes seconds by necessary nanoseconds and then add the current number of nanos to the total
?