Skip to content

Instantly share code, notes, and snippets.

@Nathaniel100
Created July 7, 2016 02:06
Show Gist options
  • Save Nathaniel100/812f037ffb28ba7e8529edc08ec68989 to your computer and use it in GitHub Desktop.
Save Nathaniel100/812f037ffb28ba7e8529edc08ec68989 to your computer and use it in GitHub Desktop.
c++11 timer class
class Timer {
public:
Timer() : beg_(clock_::now()) {}
void reset() { beg_ = clock_::now(); }
double elapsed() const {
return std::chrono::duration_cast<second_>(clock_::now() - beg_).count();
}
private:
typedef std::chrono::high_resolution_clock clock_;
typedef std::chrono::duration<double, std::ratio<1> > second_;
std::chrono::time_point<clock_> beg_;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment