-
-
Save simonrw/2058785 to your computer and use it in GitHub Desktop.
Add on file for https://gist.github.com/2057852
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 <sys/time.h> // for gettimeofday() | |
class StopWatch { | |
timeval started; | |
std::string msg; | |
public: | |
StopWatch(const std::string& m): msg(m) | |
{ gettimeofday(&started, NULL); } | |
~StopWatch() { | |
std::cerr << msg << " " << msecs() << " ms" << std::endl; | |
} | |
unsigned int usecs() const { | |
timeval t2; | |
gettimeofday(&t2, NULL); | |
return (t2.tv_sec - started.tv_sec) * 1000000 + (t2.tv_usec - started.tv_usec); | |
} | |
float msecs() const { | |
unsigned int u = usecs(); | |
return (float)u / 1000.; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment