A C++ chrono clock supplies a time source and defines its time-point type, tick period, and whether it is steady. Call its static now() function to obtain the current time; the result has the clock’s time_point type. section 4.3.1
The clock properties determine how its readings can be interpreted and used:
- The period typedef gives a fractional-second tick period, but a runtime-varying clock’s observed period is not guaranteed to match it. section 4.3.1
- A steady clock ticks uniformly and cannot be adjusted. system_clock may move backward when adjusted, so steady clocks are important for timeout calculations. section 4.3.1
- A time_point counts units of duration from its clock’s epoch. Add or subtract durations to form deadlines; subtract time points from the same clock to measure elapsed time. section 4.3.3
auto start=std::chrono::high_resolution_clock::now(); do_something(); auto stop=std::chrono::high_resolution_clock::now(); std::cout<<"do_something() took " <<std::chrono::duration<double,std::chrono::seconds>(stop-start).count() <<" seconds"<<std::endl;
This timing example calls high_resolution_clock::now() before and after work, then converts the difference to seconds. section 4.3.3




