File tree 1 file changed +14
-11
lines changed
1 file changed +14
-11
lines changed Original file line number Diff line number Diff line change @@ -30,10 +30,8 @@ class stopwatch
30
30
31
31
clock_t m_start;
32
32
duration_t m_elapsed;
33
- #if Z3DEBUG
34
33
bool m_running = false ;
35
- #endif
36
-
34
+
37
35
// FIXME: just use auto with VS 2015+
38
36
static clock_t get () {
39
37
return std::chrono::steady_clock::now ();
@@ -50,27 +48,32 @@ class stopwatch
50
48
51
49
void reset () {
52
50
m_elapsed = duration_t::zero ();
53
- DEBUG_CODE (m_running = false ;);
54
51
}
55
52
56
53
void start () {
57
- // SASSERT(!m_running);
58
- DEBUG_CODE (m_running = true ;);
59
- m_start = get ();
54
+ if (!m_running) {
55
+ m_start = get ();
56
+ m_running = true ;
57
+ }
60
58
}
61
59
62
60
void stop () {
63
- // SASSERT(m_running);
64
- DEBUG_CODE (m_running = false ;);
65
- m_elapsed += get () - m_start;
61
+ if (m_running) {
62
+ m_elapsed += get () - m_start;
63
+ m_running = false ;
64
+ }
66
65
}
67
66
68
67
double get_seconds () const {
68
+ if (m_running) {
69
+ const_cast <stopwatch*>(this )->stop ();
70
+ const_cast <stopwatch*>(this )->start ();
71
+ }
69
72
return std::chrono::duration_cast<std::chrono::milliseconds>(m_elapsed).count () / 1000.0 ;
70
73
}
71
74
72
75
double get_current_seconds () const {
73
- return std::chrono::duration_cast<std::chrono::milliseconds>( get () - m_start). count () / 1000.0 ;
76
+ return get_seconds () ;
74
77
}
75
78
};
76
79
You can’t perform that action at this time.
0 commit comments