Created
September 16, 2015 15:25
-
-
Save jwakely/2ca40c29c14dd6e30132 to your computer and use it in GitHub Desktop.
Portable timer class from http://scottmeyers.blogspot.co.uk/2015/09/should-you-be-using-something-instead.html
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> | |
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