Skip to content

Instantly share code, notes, and snippets.

@jwakely
Created September 16, 2015 15:25
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jwakely/2ca40c29c14dd6e30132 to your computer and use it in GitHub Desktop.
#include <chrono>
class WinTimer {
public:
// create and start timer
WinTimer() { reset(); }
// return ticks since timer creation or last reset
auto ticks() const
{
return (clock::now() - mTimeStart).count();
}
void reset() { mTimeStart = clock::now(); }
static auto ticksPerSecond()
{
double den = clock::duration::period::den;
return den / clock::duration::period::num;
}
private:
using clock = std::chrono::high_resolution_clock;
clock::time_point mTimeStart;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment