1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
#include "MesurePrecision.h"
/**
Constructor
Just initialize lastError string
*/
CMesurePrecision::CMesurePrecision()
{
strncpy(lastError,"No Error",9);
}
/**
Destructor
Does nothing ... no dynamic allocation
*/
CMesurePrecision::~CMesurePrecision(){}
/**
Start counting time...
Return true if the systems has a performance counter
\return bool
*/
bool CMesurePrecision::Start()
{
if (!QueryPerformanceFrequency(&frequence))
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
::GetLastError(), 0, (LPTSTR) &lpMsgBuf, 0, NULL);
strcpy(lastError,(LPCSTR)lpMsgBuf);
LocalFree( lpMsgBuf );
return false;
}
if(!QueryPerformanceCounter (&debut))
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, ::GetLastError(), 0, (LPTSTR) &lpMsgBuf, 0, NULL);
strcpy(lastError,(LPCSTR)lpMsgBuf);
LocalFree( lpMsgBuf );
return false;
}
strncpy(lastError,"No Error",9);
return true;
}
/**
Retrieves the difference of the current value of the high-resolution performance counter
and the value when Start() has been called.
\return double
*/
double CMesurePrecision::GetTimeFromStart()
{
if (!QueryPerformanceCounter (&fin))
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
::GetLastError(), 0, (LPTSTR) &lpMsgBuf, 0, NULL);
strcpy(lastError,(LPCSTR)lpMsgBuf);
LocalFree( lpMsgBuf );
return 0;
}
strncpy(lastError,"No Error",9);
return ((double)((__int64)fin.QuadPart)-((__int64)debut.QuadPart)) /
(double)frequence.QuadPart;
}
/**
Get the text for the last error (Time message)
\return char *
*/
char * CMesurePrecision::GetLastError()
{
return lastError;
} |
Partager