Last active
August 29, 2015 14:21
-
-
Save svdamani/47b045c82cf9cfb8a392 to your computer and use it in GitHub Desktop.
C++ 11 Timer class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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