13#include <spdlog/spdlog.h>
17#define TIMER_RESET(_x) _x.reset()
18#define TIMER_PRINT_ELAPSED(_x) _x.printElapsed()
19#define TIMER_PRINT_MUPS(_x) _x.printMUPS()
20#define TIMER_UPDATE_MOLECULES(_x, _y) _x.incrementMoleculeUpdates(_y)
22#define TIMER_RESET(_x) (void)0
23#define TIMER_PRINT_ELAPSED(_x) (void)0
24#define TIMER_PRINT_MUPS(_x) (void)0
25#define TIMER_UPDATE_MOLECULES(_x, _y) (void)0
32 std::chrono::time_point<std::chrono::high_resolution_clock>
m_start;
40 SPDLOG_TRACE(
"Created a new blank timer... you shouldn't be seeing this if you want to measure runtime!");
44 inline void reset() {
m_start = std::chrono::high_resolution_clock::now(); }
52 template <
typename T>
inline auto elapsed()
const {
53 return std::chrono::duration_cast<T>(std::chrono::high_resolution_clock::now() -
m_start).count();
65 auto elapsedInMillis = elapsed<std::chrono::milliseconds>();
66 auto elapsedInSecs = elapsedInMillis * 0.001;
67 SPDLOG_INFO(
"Elapsed: {}ms ({}s)", elapsedInMillis, elapsedInSecs);
72 auto elapsedInSec = (elapsed<std::chrono::milliseconds>() * 0.001);
73 SPDLOG_INFO(
"Molecule Updates per Second (MUPS): {}",
static_cast<double>(
m_moleculeUpdates) / elapsedInSec);
Utility functions for console input / output.
Class used to measure runtime performance and log molecule updates per second (MUPS).
Definition Timer.h:29
Timer()
Constructs a new Timer.
Definition Timer.h:39
void printElapsed() const
Prints the elapsed time.
Definition Timer.h:64
void incrementMoleculeUpdates(long summand)
Increments the total number of molecule updates by a given amount.
Definition Timer.h:61
void reset()
Resets the start time.
Definition Timer.h:44
auto elapsed() const
Gets the elapsed time since the start.
Definition Timer.h:52
std::chrono::time_point< std::chrono::high_resolution_clock > m_start
The start time of the timing process.
Definition Timer.h:32
long m_moleculeUpdates
The total number of molecule updates in the given timeframe.
Definition Timer.h:35
void printMUPS() const
Prints the molecule updates per second.
Definition Timer.h:71