hsf-training / cpluspluscourse

C++ Course Taught at CERN, from Sebastien Ponce (LHCb)
Apache License 2.0
168 stars 65 forks source link

Present C++ timing features #409

Closed sponce closed 2 weeks ago

sponce commented 1 year ago

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";
bernhardmgruber commented 1 year ago
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!

bernhardmgruber commented 1 year ago

I changed the milestone to the summer course, because it's an advanced topic.

hageboeck commented 2 weeks ago

This was completed in #524