Skip to content

Instantly share code, notes, and snippets.

@svenstaro
Created November 19, 2015 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svenstaro/44b99684749c538d2722 to your computer and use it in GitHub Desktop.
Save svenstaro/44b99684749c538d2722 to your computer and use it in GitHub Desktop.
#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