Created
April 1, 2014 19:50
-
-
Save foobit/9921703 to your computer and use it in GitHub Desktop.
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
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