Skip to content

Present C++ timing features #409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sponce opened this issue Feb 23, 2023 · 3 comments
Closed

Present C++ timing features #409

sponce opened this issue Feb 23, 2023 · 3 comments
Assignees
Labels
Advanced Content for the "advanced" course

Comments

@sponce
Copy link
Contributor

sponce commented Feb 23, 2023

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";
@sponce sponce added this to the March23 milestone Feb 23, 2023
@sponce sponce added the Advanced Content for the "advanced" course label Feb 23, 2023
@bernhardmgruber
Copy link
Contributor

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 bernhardmgruber modified the milestones: March23, Summer23 Feb 23, 2023
@bernhardmgruber
Copy link
Contributor

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

@hageboeck
Copy link
Contributor

This was completed in #524

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Advanced Content for the "advanced" course
Projects
None yet
Development

No branches or pull requests

3 participants