|
|
- #pragma once
-
- #include <chrono>
-
- namespace vlc
- {
- struct Timer
- {
- using time_point = std::chrono::high_resolution_clock::time_point;
-
- time_point start_time;
- double duration = 0; // Duration between last call of end and start_time
- double total_duration = 0;
-
- static inline time_point now()
- {
- return std::chrono::high_resolution_clock::now();
- }
-
- static inline double ms_duration_between(const time_point start_time, const time_point end_time)
- {
- std::chrono::duration<double, std::milli> fp_ms = end_time - start_time;
- return fp_ms.count();
- }
-
- void reset()
- {
- duration = total_duration = 0;
- }
-
- void start()
- {
- start_time = now();
- }
-
- double stop()
- {
- auto end_time = now();
- duration = ms_duration_between(start_time, end_time);
-
- total_duration += duration;
-
- return duration;
- }
- };
- }
|