cpluspluscourse
cpluspluscourse copied to clipboard
Present C++ timing features
Mainly the chrono library, including clocks, time_point and duration so that people can easily do dedicated timing of a few lines of code, basically though code like :
#include <chrono>
// other clocktypes to high_resolution_clock are steady_clock or system_clock
// see https://www.modernescpp.com/index.php/the-three-clocks for details
std::chrono::high_resolution_clock clock;
clock::time_point startTime = clock::now();
... // code to be timed
std::chrono::duration<float> ticks = clock::now() - startTime;
auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration);
std::cout << "it took " << duration.count() << " ticks, that is " << millis.count() << " ms\n";
std::chrono::high_resolution_clock clock;
Wow, I have never seen anyone create an instance of a clock :D I did not know that works!
I changed the milestone to the summer course, because it's an advanced topic.