Quantcast
Channel: Measuring the runtime of a C++ code? - Stack Overflow
Viewing all articles
Browse latest Browse all 8

Answer by rwp for Measuring the runtime of a C++ code?

$
0
0

You could also try some timer classes that start and stop automatically, and gather statistics on the average, maximum and minimum time spent in any block of code, as well as the number of calls. These cxx-rtimer classes are available on GitHub, and offer support for using std::chrono, clock_gettime(), or boost::posix_time as a back-end clock source.

With these timers, you can do something like:

void timeCriticalFunction() {    static rtimers::cxx11::DefaultTimer timer("expensive");    auto scopedStartStop = timer.scopedStart();    // Do something costly...}

with timing stats written to std::cerr on program completion.


Viewing all articles
Browse latest Browse all 8

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>