jak-project/common/util/Timer.h

46 lines
744 B
C
Raw Normal View History

#pragma once
2020-08-22 23:30:17 -04:00
#include <cstdint>
#include <ctime>
#include "common/util/Assert.h"
2020-08-22 23:30:17 -04:00
/*!
* Timer for measuring time elapsed with clock_monotonic
*/
class Timer {
public:
/*!
* Construct and start timer
*/
explicit Timer() { start(); }
#ifdef _WIN32
int clock_gettime_monotonic(struct timespec* tv) const;
2020-08-22 23:30:17 -04:00
#endif
/*!
* Start the timer
*/
void start();
/*!
* Get milliseconds elapsed
*/
double getMs() const { return (double)getNs() / 1.e6; }
2020-08-22 23:30:17 -04:00
double getUs() const { return (double)getNs() / 1.e3; }
2020-08-22 23:30:17 -04:00
/*!
* Get nanoseconds elapsed
*/
int64_t getNs() const;
2020-08-22 23:30:17 -04:00
/*!
* Get seconds elapsed
*/
double getSeconds() const { return (double)getNs() / 1.e9; }
2020-08-22 23:30:17 -04:00
struct timespec _startTime = {};
};