chrono
Need to better understand how std::chrono
works, since there are many different implementations it seems. std::chrono
in C++ provides tools for time-related functions. It has three main concepts:
- Duration
- Time point
- Clock
1. Duration
- Duration: Represents a time span or interval. It’s a count of ticks with a specific time unit (seconds, milliseconds, etc.).
The type std::chrono::duration
is templated and can represent time in any units, not just seconds.
2. Time Point
- Time Point: A specific point in time relative to a clock.
Time point
3. Clock
- Clock: Tracks current time. Three common types:
system_clock
: Wall clock, can be converted to/from time_t (system time).steady_clock
: Monotonic clock, always moves forward.high_resolution_clock
: Provides highest resolution, often alias of one of the above.
System clock vs steady clock?
- Steady clock represents a monotonic clock that never goes backward. Once the clock starts, it continues ticking without adjustments for system time changes or drift.
The steady clock is best for measuring time interval. Source: https://stackoverflow.com/questions/31552193/difference-between-steady-clock-vs-system-clock
Also see ROS Clock.
Example