Skip to content

Instantly share code, notes, and snippets.

@foobit
Created April 1, 2014 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foobit/9921703 to your computer and use it in GitHub Desktop.
Save foobit/9921703 to your computer and use it in GitHub Desktop.
class Stopwatch {
using clock = std::chrono::high_resolution_clock;
bool is_running() const { return stop_time_ == clock::time_point::min(); }
clock::time_point end_time() const { return is_running() ? clock::now() : stop_time_; }
clock::time_point begin_time_{clock::now()}, stop_time_{clock::time_point::min()};
public:
void stop() { if (is_running()) stop_time_ = clock::now(); }
clock::duration elapsed() const { return end_time() - begin_time_; }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment