Skip to content

Instantly share code, notes, and snippets.

@svdamani
Last active August 29, 2015 14:21
Show Gist options
  • Save svdamani/47b045c82cf9cfb8a392 to your computer and use it in GitHub Desktop.
Save svdamani/47b045c82cf9cfb8a392 to your computer and use it in GitHub Desktop.
C++ 11 Timer class
#include <chrono>
#include <thread>
template <typename T = std::chrono::milliseconds>
class Timer {
typedef std::chrono::high_resolution_clock clock;
public:
Timer() : start(clock::now()) {}
inline void reset() { start = clock::now(); }
inline void sleep(int n) const { std::this_thread::sleep_for(T(n)); }
inline double elapsed() const {
return std::chrono::duration_cast<T>(clock::now() - start).count();
}
private:
std::chrono::time_point<clock> start;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment