Add Stopwatch
[android/external-libkmsxx.git] / libkms++util / stopwatch.h
1 #include <chrono>
3 class Stopwatch
4 {
5 public:
6         void start()
7         {
8                 m_start = std::chrono::steady_clock::now();
9         }
11         double elapsed_s() const
12         {
13                 return std::chrono::duration<double>(std::chrono::steady_clock::now() - m_start).count();
14         }
16         double elapsed_ms() const
17         {
18                 return std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - m_start).count();
19         }
21         double elapsed_us() const
22         {
23                 return std::chrono::duration<double, std::micro>(std::chrono::steady_clock::now() - m_start).count();
24         }
26 private:
27         std::chrono::steady_clock::time_point m_start;
28 };