timer.h
#ifndef CMU462_TIMER_H
#define CMU462_TIMER_H
#include "CMU462.h"
#include <chrono>
namespace CMU462 {
class Timer {
public:
inline void start() {
t0 = std::chrono::steady_clock::now();
}
inline void stop() {
t1 = std::chrono::steady_clock::now();
}
inline double duration() {
return (std::chrono::duration<double>(t1 - t0)).count();
}
private:
std::chrono::time_point<std::chrono::steady_clock> t0;
std::chrono::time_point<std::chrono::steady_clock> t1;
};
} // namespace CMU462
#endif //CMU462_TIMER_H
CMU462
Definition: CMU462.h:8
CMU462::Timer::duration
double duration()
Return duration between the last call to start and last call to stop.
Definition: timer.h:32
CMU462::Timer::stop
void stop()
Stops the timer.
Definition: timer.h:25
CMU462::Timer::start
void start()
Starts the timer.
Definition: timer.h:18
CMU462::Timer
A basic timer class.
Definition: timer.h:12