2016-04-24 02:45:01 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
|
2017-02-18 21:36:50 +08:00
|
|
|
namespace utils {
|
|
|
|
|
2017-08-30 23:17:43 +08:00
|
|
|
// This class is threadsafe.
|
2017-07-15 01:33:45 +08:00
|
|
|
class Timer {
|
2017-02-18 18:54:37 +08:00
|
|
|
public:
|
2019-01-15 18:11:06 +08:00
|
|
|
Timer() : start_time_(std::chrono::steady_clock::now()) {}
|
|
|
|
|
|
|
|
template <typename TDuration = std::chrono::duration<double>>
|
|
|
|
TDuration Elapsed() const {
|
|
|
|
return std::chrono::duration_cast<TDuration>(
|
|
|
|
std::chrono::steady_clock::now() - start_time_);
|
2017-02-18 18:54:37 +08:00
|
|
|
}
|
2016-12-22 22:51:16 +08:00
|
|
|
|
2017-02-18 18:54:37 +08:00
|
|
|
private:
|
2019-01-15 18:11:06 +08:00
|
|
|
std::chrono::steady_clock::time_point start_time_;
|
2016-04-24 02:45:01 +08:00
|
|
|
};
|
2018-04-22 14:31:09 +08:00
|
|
|
|
|
|
|
} // namespace utils
|