Created
March 12, 2014 09:36
-
-
Save fbaeuerlein/9503708 to your computer and use it in GitHub Desktop.
scope guard like class for measuring duration (from construction to destruction)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <boost/chrono/chrono_io.hpp> | |
class MeasureDuration | |
{ | |
public: | |
MeasureDuration(const std::string & name = "unknown" ) | |
{ | |
_duration = 0; | |
_name = name; | |
_start = boost::chrono::high_resolution_clock::now(); | |
} | |
~MeasureDuration() | |
{ | |
boost::chrono::nanoseconds ns = boost::chrono::high_resolution_clock::now() - _start; | |
_duration = (double) ns.count() / (1000. * 1000.); | |
std::cerr << "duration of " << _name << " in ms: " << _duration << std::endl; | |
} | |
private: | |
double _duration; | |
std::string _name; | |
boost::chrono::high_resolution_clock::time_point _start; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment