Skip to content

Instantly share code, notes, and snippets.

@johanngerell
Last active February 23, 2016 13:29
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 johanngerell/8a66157db972dfa7b541 to your computer and use it in GitHub Desktop.
Save johanngerell/8a66157db972dfa7b541 to your computer and use it in GitHub Desktop.
#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