Last active
February 23, 2016 13:29
-
-
Save johanngerell/8a66157db972dfa7b541 to your computer and use it in GitHub Desktop.
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
#pragma once | |
#include <chrono> | |
namespace jg | |
{ | |
class stopwatch final | |
{ | |
using clock = std::chrono::high_resolution_clock; | |
clock::time_point m_start = clock::now(); | |
template <typename T> | |
typename T::rep duration_rep() const | |
{ | |
return std::chrono::duration_cast<T>(clock::now() - m_start).count(); | |
} | |
public: | |
std::chrono::microseconds::rep us() const | |
{ | |
return duration_rep<std::chrono::microseconds>(); | |
} | |
std::chrono::milliseconds::rep ms() const | |
{ | |
return duration_rep<std::chrono::milliseconds>(); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment