diff options
author | Johannes Stoelp <johannes.stoelp@gmail.com> | 2023-08-02 00:19:41 +0200 |
---|---|---|
committer | Johannes Stoelp <johannes.stoelp@gmail.com> | 2023-08-31 19:41:45 +0200 |
commit | a28790b91d89002edb27dd1bc3997b1d03a94d7e (patch) | |
tree | d396bb0042b2c923ea450d3e536198d68685b233 /timer.h | |
parent | 58bae306abde95da78f698408ac9d580d5a2b1d7 (diff) | |
download | cpp-utils-a28790b91d89002edb27dd1bc3997b1d03a94d7e.tar.gz cpp-utils-a28790b91d89002edb27dd1bc3997b1d03a94d7e.zip |
timer: add assertions to test
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(); |