Add Stopwatch
authorTomi Valkeinen <tomi.valkeinen@ti.com>
Sat, 4 Jun 2016 18:58:59 +0000 (21:58 +0300)
committerTomi Valkeinen <tomi.valkeinen@ti.com>
Sat, 4 Jun 2016 19:33:53 +0000 (22:33 +0300)
libkms++util/stopwatch.h [new file with mode: 0644]

diff --git a/libkms++util/stopwatch.h b/libkms++util/stopwatch.h
new file mode 100644 (file)
index 0000000..9b60fa1
--- /dev/null
@@ -0,0 +1,28 @@
+#include <chrono>
+
+class Stopwatch
+{
+public:
+       void start()
+       {
+               m_start = std::chrono::steady_clock::now();
+       }
+
+       double elapsed_s() const
+       {
+               return std::chrono::duration<double>(std::chrono::steady_clock::now() - m_start).count();
+       }
+
+       double elapsed_ms() const
+       {
+               return std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - m_start).count();
+       }
+
+       double elapsed_us() const
+       {
+               return std::chrono::duration<double, std::micro>(std::chrono::steady_clock::now() - m_start).count();
+       }
+
+private:
+       std::chrono::steady_clock::time_point m_start;
+};