diff options
author | B. Stack <bgstack15@gmail.com> | 2023-06-20 07:46:53 -0400 |
---|---|---|
committer | B. Stack <bgstack15@gmail.com> | 2023-06-20 07:46:53 -0400 |
commit | f76994f1fb3e25c4563c9d8afce6bbc86701d1d2 (patch) | |
tree | b39389163603195a0169af57712eb0765e5c11f4 /zen/perf.h | |
parent | add upstream 12.3 (diff) | |
download | FreeFileSync-12.4.tar.gz FreeFileSync-12.4.tar.bz2 FreeFileSync-12.4.zip |
add upstream 12.412.4
Diffstat (limited to 'zen/perf.h')
-rw-r--r-- | zen/perf.h | 30 |
1 files changed, 10 insertions, 20 deletions
@@ -40,45 +40,35 @@ namespace zen class StopWatch { public: - explicit StopWatch(bool startPaused = false) : paused_(startPaused) {} + explicit StopWatch(bool startPaused = false) + { + if (startPaused) + startTime_ = {}; + } - bool isPaused() const { return paused_; } + bool isPaused() const { return startTime_ == std::chrono::steady_clock::time_point{}; } void pause() { - if (!paused_) - { - paused_ = true; - elapsedUntilPause_ += std::chrono::steady_clock::now() - startTime_; - } + if (!isPaused()) + elapsedUntilPause_ += std::chrono::steady_clock::now() - std::exchange(startTime_, {}); } void resume() { - if (paused_) - { - paused_ = false; + if (isPaused()) startTime_ = std::chrono::steady_clock::now(); - } - } - - void restart() - { - paused_ = false; - startTime_ = std::chrono::steady_clock::now(); - elapsedUntilPause_ = std::chrono::nanoseconds::zero(); } std::chrono::nanoseconds elapsed() const { auto elapsedTotal = elapsedUntilPause_; - if (!paused_) + if (!isPaused()) elapsedTotal += std::chrono::steady_clock::now() - startTime_; return elapsedTotal; } private: - bool paused_; std::chrono::steady_clock::time_point startTime_ = std::chrono::steady_clock::now(); std::chrono::nanoseconds elapsedUntilPause_{}; //std::chrono::duration is uninitialized by default! WTF! When will this stupidity end! }; |