summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorU. Artie Eoff <ullysses.a.eoff@intel.com>2016-10-26 13:24:15 -0700
committerSean V Kelley <seanvk@posteo.de>2016-10-28 13:11:53 -0700
commit1eae2167650c5159b510534d022cf79e38c9799c (patch)
tree68ea2e8285e0052a6929ec1252f8f830dc895864 /test
parent63b98a529522385254c0f50dfb8e566679017c89 (diff)
test: add a timer class
The timer is useful to quickly instrument various sections of code during test development optimization tasks or other timing needs. Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com> Reviewed-by: Sean V Kelley <seanvk@posteo.de>
Diffstat (limited to 'test')
-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