Created
October 4, 2012 21:06
-
-
Save travisperson/3836464 to your computer and use it in GitHub Desktop.
High Frequency Timer for windows
This file contains hidden or 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
// High Frequency Timer | |
// | |
// This is a simple timer for windows. | |
// | |
// QueryPerformanceCounter | |
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms644904(v=vs.85).aspx | |
// | |
// QueryPerformanceFrequency | |
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms644905(v=vs.85).aspx | |
// | |
// | |
// Example | |
// Timer t; | |
// | |
// t.start() | |
// | |
// for ( unsigned int i = 0; i < 1000; i++ ) | |
// { | |
// std::cout << "Elapsed since start: " << t.getSeconds() << std::endl; | |
// } | |
#ifndef INLINE_TIMER_H | |
#define INLINE_TIMER_H | |
include <windows.h> | |
class Timer | |
{ | |
public: | |
inline void start() | |
{ | |
QueryPerformanceCounter(&start); | |
}; | |
inline float getSeconds() const | |
{ | |
LARGE_INTEGER now; | |
LARGE_INTEGER freq; | |
QueryPerformanceCounter(&now); | |
QueryPerformanceFrequency(&freq); | |
return (now.QuadPart - start.QuadPart) / static_cast<float>(freq.QuadPart); | |
}; | |
private: | |
LARGE_INTEGER start; | |
}; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment