Chrono stable_clock does not give the correct result?

I have one line of code in the application server code that gets the timestamp value using steady_clock , as shown below:

 uint64_t now = duration_cast<milliseconds>(steady_clock::now().time_since_epoch()).count(); 

Now we have two systems machineA, which runs Ubuntu 12 (gcc 4.6.3 compiler) and machineB, which runs Ubuntu 14 (gcc 4.8.2 compiler) .

Now we compile our application server code using make on another Ubuntu 12 VM (which has 4.7.3 compiler) , and then copy the tar file that is generated on machineA and start our application server. After starting, the above line of code outputs a value similar to this in machineA:

 1439944652967 

Now we also compile the same application server code using make on another Ubuntu 14 VM (which has 4.8.2 compiler) , and then copy the tar file that will be generated on machineB and start our application server. After starting, the above line of code outputs a value similar to this in machineB:

 10011360 

Do you see the difference right? I am confused, why is it a difference, I canโ€™t understand it? All the code and everything is the same. Does anyone have an explanation about this and how can I fix this?

If necessary, I can try to add debugging code to understand what is wrong to understand this problem.

+7
c ++ gcc ubuntu chrono
source share
1 answer

I am afraid there is some confusion as to what std::steady_clock .

time_since_epoch gives the duration from the beginning of the hours, not necessarily the Unix era. steady_clock guarantees only monotonous increase. This means that steady_clock will always move forward and that it will never decrease.

There is no guarantee that steady_clock will represent anything meaningful. This may be the duration since the start of the program, the duration of the computer, the duration from the very last Tuesday or almost anything, while it continues to move forward.

In other words, steady_clock is actually not all that useful for real-time real-time . It is only useful to measure time. It can include any situation in which you have a point in time A and time in time B, and you are interested in learning about the duration between them: a comparative analysis, estimates of progress, etc.

If you are looking for real time, you should look at std::system_clock , a clock representing the time of the system (i.e. the time of the operating system). Itโ€™s great to say time, but itโ€™s rather useless for measuring differentials, since it is not guaranteed to be monotonous and almost certainly does not give daylight saving time, users customize their watches and other events that can change real world time.

+13
source share

All Articles