Using clocks, timers, and ratios
Before getting into more examples with clocks and timers, we first have to get a better understanding of how the chrono library defines a duration.
As we saw in the previous example, a duration is the distance between two points of time, called timepoints. In our previous example, these were the start
and end
timepoints.
Figure 8.1 – Timepoint and duration
The duration itself is a combination of the count of ticks and a fraction that represents the time in seconds from one tick to the next. The fraction is represented by the std::ratio
class. Here are some examples:
using namespace std::chrono; constexpr std::chrono::duration<int, std::ratio<1>> Â Â six_minutes_1{360}; constexpr std::chrono::duration<double, std::ratio<3600>> Â Â six_minutes_2{0.1}; constexpr std::chrono::minutes six_minutes_3{6}; constexpr auto six_minutes_4{6min}; std::cout << six_minutes_1 <...