I am sampling the system time at 500ms intervals using std::chrono. On each sample, I subtract the current time from the last time, and accumulate the result. However after 1hr, the total accumulated time is about 50ms faster for an hour. Does anybody know the reason?The code of get system time as below:
void serverTimeResponse(long serverTime) {
long localTime =(long)std::chrono::duration_cast<std::chrono::microseconds(now.time_since_epoch()).count();
long duration = localtime - serverTime;
writeToCsvFile(duration);
}
The serverTimeResponse will be called every 500ms because server will return by socket, I record the duration into csv file, after 1 hour, I see the last row duration is more 50ms than the first row duration in csv file. I doubt whether the chrono library has some issue for get the system time.
Ran on ubuntu 18.04
now
? How do you know it's changed by 50ms? – Alan Birtles