So I read this boost docs but I still do not see how to do such simple thing
int main() {
//stuff
startTimer();
// do stuff
int i =getTimerValue();
//stuff
}
so to get execution time of stuff that I've done. How to do such thing?
Use boost::timer
#include <boost/timer.hpp>
int main() {
boost::timer t; // start timing
...
double elapsed_time = t.elapsed();
...
}
Note that the destuctor of a boost::progress_timer
will display the time. So use scope if your aim is just to display time elapsed in the middle of a function.
int main() {
{
boost::progress_timer t; // start timing
...
} // elapsed time displayed here when t is destructed
...
}
Replace this with
#include <boost/progress.hpp>
void function()
{
progress_timer t; // start timing
// do stuff
return 0;
}
and you will get what you want, not using printf
though.
Timer starts on construction and displays on destruction (ie. at fn exit.). This is a typically RAII way of doing scoped tasks (timing, locking etc.) in C++.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With