Skip to content

Instantly share code, notes, and snippets.

@svenstaro
Created Nov 19, 2015
Embed
What would you like to do?
#ifndef TIMER_HPP
#define TIMER_HPP
#include <chrono>
class Timer {
public:
Timer() {
m_start = std::chrono::steady_clock::now();
}
template<typename T = std::chrono::milliseconds>
double elapsed() {
auto end = std::chrono::steady_clock::now();
auto delta = end - m_start;
auto msdelta = std::chrono::duration<double, typename T::period>(delta);
return msdelta.count();
}
private:
std::chrono::time_point<std::chrono::steady_clock> m_start;
};
#endif /* end of include guard: TIMER_HPP */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment