17 Timer(
const std::string &message,
const std::string &filename =
"")
18 : m_Start(
std::chrono::high_resolution_clock::now()), m_Message(message), m_Filename(filename)
25 const double duration =
get();
26 std::cout << m_Message << duration <<
" seconds" << std::endl;
29 if(!m_Filename.empty()) {
30 std::ofstream output(m_Filename, std::ios::app);
31 output << duration << std::endl;
41 auto now = std::chrono::high_resolution_clock::now();
42 std::chrono::duration<double> duration = now - m_Start;
43 return duration.count();
50 const std::chrono::time_point<std::chrono::high_resolution_clock> m_Start;
51 const std::string m_Message;
52 const std::string m_Filename;
63 TimerAccumulate(
double &accumulator) : m_Start(
std::chrono::high_resolution_clock::now()), m_Accumulator(accumulator)
68 m_Accumulator +=
get();
77 auto now = std::chrono::high_resolution_clock::now();
78 std::chrono::duration<double> duration = now - m_Start;
79 return duration.count();
86 std::chrono::time_point<std::chrono::high_resolution_clock> m_Start;
87 double &m_Accumulator;
~Timer()
Stop the timer and print current elapsed time to terminal.
Definition: userproject/include/timer.h:23
~TimerAccumulate()
Definition: userproject/include/timer.h:66
TimerAccumulate(double &accumulator)
Definition: userproject/include/timer.h:63
Timer(const std::string &message, const std::string &filename="")
Create a new Timer with the specified name and optionally a filename to append time to...
Definition: userproject/include/timer.h:17
A timer which adds its elapsed time to an accumulator variable on destruction.
Definition: userproject/include/timer.h:60