1 #include <chrono> 2 3 class Stopwatch 4 { 5 public: start()6 void start() 7 { 8 m_start = std::chrono::steady_clock::now(); 9 } 10 elapsed_s()11 double elapsed_s() const 12 { 13 return std::chrono::duration<double>(std::chrono::steady_clock::now() - m_start).count(); 14 } 15 elapsed_ms()16 double elapsed_ms() const 17 { 18 return std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - m_start).count(); 19 } 20 elapsed_us()21 double elapsed_us() const 22 { 23 return std::chrono::duration<double, std::micro>(std::chrono::steady_clock::now() - m_start).count(); 24 } 25 26 private: 27 std::chrono::steady_clock::time_point m_start; 28 }; 29