From 7823117776d6727b06e08e3f7918582670ba7de6 Mon Sep 17 00:00:00 2001 From: Arie Gurfinkel Date: Sat, 31 Aug 2019 21:35:35 -0400 Subject: [PATCH] Restore expected behavior to stopwatch --- src/util/stopwatch.h | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/util/stopwatch.h b/src/util/stopwatch.h index 127e9d9c0..a2821e7ec 100644 --- a/src/util/stopwatch.h +++ b/src/util/stopwatch.h @@ -30,10 +30,8 @@ class stopwatch clock_t m_start; duration_t m_elapsed; -#if Z3DEBUG bool m_running = false; -#endif - + // FIXME: just use auto with VS 2015+ static clock_t get() { return std::chrono::steady_clock::now(); @@ -50,27 +48,32 @@ public: void reset() { m_elapsed = duration_t::zero(); - DEBUG_CODE(m_running = false;); } void start() { - // SASSERT(!m_running); - DEBUG_CODE(m_running = true;); - m_start = get(); + if (!m_running) { + m_start = get(); + m_running = true; + } } void stop() { - // SASSERT(m_running); - DEBUG_CODE(m_running = false;); - m_elapsed += get() - m_start; + if (m_running) { + m_elapsed += get() - m_start; + m_running = false; + } } double get_seconds() const { + if (m_running) { + const_cast(this)->stop(); + const_cast(this)->start(); + } return std::chrono::duration_cast(m_elapsed).count() / 1000.0; } double get_current_seconds() const { - return std::chrono::duration_cast(get() - m_start).count() / 1000.0; + return get_seconds(); } };