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 <[email protected]> --- test/test_utils.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/test_utils.h b/test/test_utils.h index 007667708adb..333106c239d6 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 -- 2.1.0 _______________________________________________ Libva mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libva
