Created
April 5, 2011 01:48
-
-
Save hpcx82/902874 to your computer and use it in GitHub Desktop.
Simple timing function and class to profile program in 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
LONGLONG GetFrequency() | |
{ | |
LARGE_INTEGER qpFrequency; | |
::QueryPerformanceFrequency(&qpFrequency); | |
return qpFrequency.QuadPart; | |
} | |
double Tick() | |
{ | |
static LONGLONG llFrequency = GetFrequency(); | |
LARGE_INTEGER qpCounter; | |
::QueryPerformanceCounter(&qpCounter); | |
return qpCounter.QuadPart / (double)llFrequency; | |
} | |
// Example | |
double c1 = Tick(); | |
::Sleep(3000); | |
double c2 = Tick(); | |
class CAutoTimer | |
{ | |
public: | |
CAutoTimer() | |
{ | |
start = Tick(); | |
} | |
~CAutoTimer() | |
{ | |
double end = Tick(); | |
CString strOutput; | |
strOutput.Format(_T("Time: %4.2f seconds!"), end-start); | |
AfxMessageBox(strOutput); | |
} | |
private: | |
double start; | |
}; | |
// Example | |
{ | |
CAutoTimer auto; | |
::Sleep(3000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment