How do I use std::chrono clocks and durations?

In C++, the `` library provides a powerful way to deal with time. It includes various clocks, durations, and time point functionalities that can help with measuring time spans, and creating timers, among other uses. Below is an example demonstrating how to use `std::chrono` to measure the duration of a piece of code.

#include #include int main() { // Start measuring time auto start = std::chrono::high_resolution_clock::now(); // Code block to measure for (int i = 0; i < 1000000; ++i) { // Simulate work } // Stop measuring time auto end = std::chrono::high_resolution_clock::now(); // Calculate duration std::chrono::duration duration = end - start; std::cout << "Duration: " << duration.count() << " ms" << std::endl; return 0; }

std::chrono C++ clocks durations measure time timing code