summaryrefslogtreecommitdiff
path: root/test/test_utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_utils.h')
-rw-r--r--test/test_utils.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/test_utils.h b/test/test_utils.h
index 0076677..333106c 100644
--- a/test/test_utils.h
+++ b/test/test_utils.h
@@ -25,6 +25,7 @@
#ifndef TEST_UTILS_H
#define TEST_UTILS_H
+#include <chrono>
#include <random>
template <typename T>
@@ -46,4 +47,29 @@ private:
std::uniform_int_distribution<T> dis;
};
+class Timer
+{
+public:
+ typedef typename std::chrono::microseconds us;
+ typedef typename std::chrono::milliseconds ms;
+ typedef typename std::chrono::seconds s;
+
+ Timer() { reset(); }
+
+ template <typename T = std::chrono::microseconds>
+ typename T::rep elapsed() const
+ {
+ return std::chrono::duration_cast<T>(
+ std::chrono::steady_clock::now() - start).count();
+ }
+
+ void reset()
+ {
+ start = std::chrono::steady_clock::now();
+ }
+
+private:
+ std::chrono::steady_clock::time_point start;
+};
+
#endif // TEST_UTILS_H