December 2018
Intermediate to advanced
552 pages
12h 18m
English
On most systems, high_resolution_clock{} and steady_clock{} are the same. In general, high_resolution_clock{} represents the highest-resolution clock available as a steady clock and, as shown in the following example, the result is the same with stead_clock{}:
#include <chrono>#include <iostream>#include <unistd.h>int main(){ using namespace std::chrono; auto now1 = high_resolution_clock::now(); sleep(2); auto now2 = high_resolution_clock::now(); std::cout << "time: " << duration_cast<seconds>(now2 - now1).count() << '\n'; std::cout << "time: " << duration_cast<milliseconds>(now2 - now1).count() << '\n'; std::cout << "time: " << duration_cast<nanoseconds>(now2 - now1).count() << '\n';}// > g++ -std=c++17 ...Read now
Unlock full access