Chrono and Formatting
Chrono and Formatting
Durations, clocks, time points, and modern text formatting in one quick reference.
Chrono and Formatting
Durations, clocks, time points, and modern text formatting in one quick reference.
using namespace std::chrono_literals;
auto timeout = 250ms;
auto start = std::chrono::steady_clock::now();
steady_clock: elapsed time and benchmarking.system_clock: wall-clock time.10ms, 2s, and 5min improve readability.auto start = std::chrono::steady_clock::now();
do_work();
auto end = std::chrono::steady_clock::now();
auto elapsed = end - start;
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(elapsed);
std::format and std::printauto msg = std::format("{} took {} ms", name, ms.count());
std::print("{}\n", msg);
steady_clock for timeouts and measurements.system_clock for timestamps the user sees.std::format over hand-built stream chains when formatting gets nontrivial.