selective runtime check

Hi everyone,

I'm working on comparing different sorting algorithms' efficiency and wondering, is there any way to check a running time of a specific block of code in C++ ?

What I normally get after the program executes is total time, including how long it took to print a bunch of output numbers. I'm trying to see how long just the processing part took, excluding all the couts, initializations, etc.

Ideally speaking, is it possible to have something like a stopwatch that I can start, pause and continue internally and then return the total time measured at the end?

Thank you for any suggestions!
Check out the <chrono> library that was added in C++11:
http://www.cplusplus.com/reference/chrono/
http://en.cppreference.com/w/cpp/header/chrono

Check out the example on this page:
http://en.cppreference.com/w/cpp/chrono/high_resolution_clock/now

By the way, you should remember to test your code with various optimization options, including no optimizations and max optimizations.
Last edited on
Great info, thank you!
Topic archived. No new replies allowed.