diff options
author | B Stack <bgstack15@gmail.com> | 2020-07-22 11:37:03 -0400 |
---|---|---|
committer | B Stack <bgstack15@gmail.com> | 2020-07-22 11:37:03 -0400 |
commit | c95b3937fef3e2c63768f1b3b1dc2c898f23d91d (patch) | |
tree | 10260e25ae905564f7978b83fc4e316670f987c6 /zen/perf.h | |
parent | Merge branch '10.25' into 'master' (diff) | |
download | FreeFileSync-c95b3937fef3e2c63768f1b3b1dc2c898f23d91d.tar.gz FreeFileSync-c95b3937fef3e2c63768f1b3b1dc2c898f23d91d.tar.bz2 FreeFileSync-c95b3937fef3e2c63768f1b3b1dc2c898f23d91d.zip |
add upstream 11.0
Diffstat (limited to 'zen/perf.h')
-rw-r--r-- | zen/perf.h | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -21,9 +21,9 @@ /* Example: Aggregated function call time: - static zen::PerfTimer timer; - timer.resume(); - ZEN_ON_SCOPE_EXIT(timer.pause()); + static zen::PerfTimer perfTest(true); //startPaused + perfTest.resume(); + ZEN_ON_SCOPE_EXIT(perfTest.pause()); */ namespace zen @@ -41,6 +41,8 @@ namespace zen class StopWatch { public: + explicit StopWatch(bool startPaused = false) : paused_(startPaused) {} + bool isPaused() const { return paused_; } void pause() @@ -77,7 +79,7 @@ public: } private: - bool paused_ = false; + 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??? }; @@ -86,10 +88,13 @@ private: class PerfTimer { public: - [[deprecated]] PerfTimer() {} + [[deprecated]] explicit PerfTimer(bool startPaused = false) : watch_(startPaused) {} ~PerfTimer() { if (!resultShown_) showResult(); } + void pause () { watch_.pause(); } + void resume() { watch_.resume(); } + void showResult() { const bool wasRunning = !watch_.isPaused(); |