diff options
Diffstat (limited to 'timer.h')
-rw-r--r-- | timer.h | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -2,6 +2,7 @@ #include <ctime> namespace timer { +/// A minimal Linux watch clock. struct timer { constexpr timer() = default; @@ -17,6 +18,10 @@ struct timer { (end.tv_nsec - m_start.tv_nsec); } + constexpr void reset() { + m_nanos = 0; + } + constexpr double as_sec() const { return as_msec() / 1000.0; } @@ -36,6 +41,8 @@ struct timer { std::uint64_t m_nanos{0}; }; +/// A scoped timer to automatically start / stop a watch clock in the scope the +/// scoped_timer lives. struct scoped_timer { explicit scoped_timer(timer& t) : m_timer(t) { m_timer.start(); |