aboutsummaryrefslogtreecommitdiff
path: root/timer.h
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2023-08-02 00:19:41 +0200
committerJohannes Stoelp <johannes.stoelp@gmail.com>2023-08-31 19:41:45 +0200
commita28790b91d89002edb27dd1bc3997b1d03a94d7e (patch)
treed396bb0042b2c923ea450d3e536198d68685b233 /timer.h
parent58bae306abde95da78f698408ac9d580d5a2b1d7 (diff)
downloadcpp-utils-a28790b91d89002edb27dd1bc3997b1d03a94d7e.tar.gz
cpp-utils-a28790b91d89002edb27dd1bc3997b1d03a94d7e.zip
timer: add assertions to test
Diffstat (limited to 'timer.h')
-rw-r--r--timer.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/timer.h b/timer.h
index ce0e629..15e0497 100644
--- a/timer.h
+++ b/timer.h
@@ -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();