What is the difference between std::system_clock and std::steady_clock? (An example case that illustrate different results/behaviours would be great).
If my goal is to precisely measure execution time of functions (like a benchmark), what would be the best choice between std::system_clock, std::steady_clock and std::high_resolution_clock?
From N3376:
20.11.7.1 [time.clock.system]/1:
20.11.7.2 [time.clock.steady]/1:
20.11.7.3 [time.clock.hires]/1:
For instance, the system wide clock might be affected by something like daylight savings time, at which point the actual time listed at some point in the future can actually be a time in the past. (E.g. in the US, in the fall time moves back one hour, so the same hour is experienced “twice”) However,
steady_clockis not allowed to be affected by such things.Another way of thinking about “steady” in this case is in the requirements defined in the table of 20.11.3 [time.clock.req]/2:
That’s all the standard has on their differences.
If you want to do benchmarking, your best bet is probably going to be
std::high_resolution_clock, because it is likely that your platform uses a high resolution timer (e.g.QueryPerformanceCounteron Windows) for this clock. However, if you’re benchmarking, you should really consider using platform specific timers for your benchmark, because different platforms handle this differently. For instance, some platforms might give you some means of determining the actual number of clock ticks the program required (independent of other processes running on the same CPU). Better yet, get your hands on a real profiler and use that.