summaryrefslogtreecommitdiff
path: root/zen/perf.h
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2023-06-20 07:46:53 -0400
committerB. Stack <bgstack15@gmail.com>2023-06-20 07:46:53 -0400
commitf76994f1fb3e25c4563c9d8afce6bbc86701d1d2 (patch)
treeb39389163603195a0169af57712eb0765e5c11f4 /zen/perf.h
parentadd upstream 12.3 (diff)
downloadFreeFileSync-f76994f1fb3e25c4563c9d8afce6bbc86701d1d2.tar.gz
FreeFileSync-f76994f1fb3e25c4563c9d8afce6bbc86701d1d2.tar.bz2
FreeFileSync-f76994f1fb3e25c4563c9d8afce6bbc86701d1d2.zip
add upstream 12.412.4
Diffstat (limited to 'zen/perf.h')
-rw-r--r--zen/perf.h30
1 files changed, 10 insertions, 20 deletions
diff --git a/zen/perf.h b/zen/perf.h
index c3315717..a0cc905a 100644
--- a/zen/perf.h
+++ b/zen/perf.h
@@ -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!
};
bgstack15