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>
(cherry picked from commit
1eae2167650c5159b510534d022cf79e38c9799c)
#ifndef TEST_UTILS_H
#define TEST_UTILS_H
+#include <chrono>
#include <random>
template <typename T>
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