3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-08 18:31:49 +00:00

Restore expected behavior to stopwatch

This commit is contained in:
Arie Gurfinkel 2019-08-31 21:35:35 -04:00 committed by Nikolaj Bjorner
parent e816d16724
commit 7823117776

View file

@ -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<stopwatch*>(this)->stop();
const_cast<stopwatch*>(this)->start();
}
return std::chrono::duration_cast<std::chrono::milliseconds>(m_elapsed).count() / 1000.0;
}
double get_current_seconds() const {
return std::chrono::duration_cast<std::chrono::milliseconds>(get() - m_start).count() / 1000.0;
return get_seconds();
}
};