Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#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