pleascach/util/Timer.hpp
connellpaxton e077eeaf5d Added class to handle allocation and creation of Buffers and Image, as well as Timers.
No memory leaks detected yet.
(Fingers crossed).
2024-01-23 16:00:15 -05:00

38 lines
754 B
C++

#pragma once
#include <chrono>
/* get the time in milliseconds */
struct Timer {
std::chrono::time_point<std::chrono::steady_clock> start_time, end_time;
bool running = false;
Timer() {
start();
}
inline void start() {
start_time = std::chrono::steady_clock::now();
running = true;
}
inline void reset() {
start();
}
inline double read() {
if (running) {
auto end = std::chrono::steady_clock::now();
return std::chrono::duration_cast<std::chrono::microseconds>(end - start_time).count() / 1000.0;
}
return std::chrono::duration_cast<std::chrono::microseconds>(end_time - start_time).count() / 1000.0;
}
inline double stop() {
end_time = std::chrono::steady_clock::now();
running = false;
return read();
}
};