From c95b3937fef3e2c63768f1b3b1dc2c898f23d91d Mon Sep 17 00:00:00 2001 From: B Stack Date: Wed, 22 Jul 2020 11:37:03 -0400 Subject: add upstream 11.0 --- zen/perf.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'zen/perf.h') diff --git a/zen/perf.h b/zen/perf.h index 33005e9f..2598ea76 100644 --- a/zen/perf.h +++ b/zen/perf.h @@ -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(); -- cgit