fxos/include/fxos/util/Timer.h

49 lines
1.5 KiB
C++

//---------------------------------------------------------------------------//
// 1100101 |_ mov #0, r4 __ //
// 11 |_ <0xb380 %5c4> / _|_ _____ ___ //
// 0110 |_ 3.50 -> 3.60 | _\ \ / _ (_-< //
// |_ base# + offset |_| /_\_\___/__/ //
//---------------------------------------------------------------------------//
// fxos/util/Timer: A sime CLOCK_REALTIME timer to check performance metrics
//
// The Timer object can be used to accumulate measures of CLOCK_REALTIME for
// basic estimations of performance metrics.
//---
#ifndef FXOS_UTIL_TIMER_H
#define FXOS_UTIL_TIMER_H
#include <cstdint>
#include <string>
#include <ctime>
struct Timer
{
/* New timer with a total count of 0 */
Timer();
/* Current count in nanoseconds */
uint64_t time_ns;
/* True when running, time when the timer started running */
bool running;
struct timespec start_time;
/* Run depth (for recursive functions) */
int depth;
/* Start and stop counting. Make sure start/stop calls match in pairs */
void start();
void stop();
/* Reset the total time; reset and start */
void reset();
void restart();
/* String representation of time */
std::string format_time() const;
/* Same function for external measures, if ever needed */
static std::string format_time(uint64_t time_ns);
};
#endif /* FXOS_UTIL_TIMER_H */