From a28790b91d89002edb27dd1bc3997b1d03a94d7e Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Wed, 2 Aug 2023 00:19:41 +0200 Subject: timer: add assertions to test --- timer.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'timer.h') diff --git a/timer.h b/timer.h index ce0e629..15e0497 100644 --- a/timer.h +++ b/timer.h @@ -2,6 +2,7 @@ #include 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(); -- cgit v1.2.3