aboutsummaryrefslogtreecommitdiff
path: root/timer.h
diff options
context:
space:
mode:
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();