diff options
| author | Yong He <yonghe@outlook.com> | 2021-03-08 10:01:20 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-08 10:01:20 -0800 |
| commit | fc9968dc4fd58fab37476f48e4405c2743c5349c (patch) | |
| tree | 6119b293a5a5cc24401dde5ff54287beb28fe63b /tools/platform/performance-counter.h | |
| parent | 95ca93938f5d45f4eaf340867965bd77a1724d6c (diff) | |
Refactor window library. (#1739)
* Refactor window library.
* Fix project file
* Fix warnings.
Diffstat (limited to 'tools/platform/performance-counter.h')
| -rw-r--r-- | tools/platform/performance-counter.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tools/platform/performance-counter.h b/tools/platform/performance-counter.h new file mode 100644 index 000000000..e9e990f45 --- /dev/null +++ b/tools/platform/performance-counter.h @@ -0,0 +1,30 @@ +#ifndef PLATFORM_PERFORMANCE_COUNTER_H +#define PLATFORM_PERFORMANCE_COUNTER_H + +#include <chrono> + +namespace platform +{ +typedef std::chrono::high_resolution_clock::time_point TimePoint; +typedef std::chrono::high_resolution_clock::duration Duration; + +class PerformanceCounter +{ +public: + static inline TimePoint now() + { + return std::chrono::high_resolution_clock::now(); + } + static inline Duration getElapsedTime(TimePoint counter) { return now() - counter; } + static inline float getElapsedTimeInSeconds(TimePoint counter) + { + return (float)toSeconds(now() - counter); + } + static inline double toSeconds(Duration duration) + { + return std::chrono::duration<float>(duration).count(); + } +}; +} // namespace platform + +#endif |
