//z 2014-06-19 17:18:49 L.195'24071 BG57IV3@XCL T1202481319.K.F636940351 [T22,L436,R14,V351]
c++ timer 计时
//z 2014-06-19 17:18:49 L.195'24071 BG57IV3@XCL T1202481319.K.F636940351 [T22,L436,R14,V351]
//z 2014-06-20 14:28:39 L.194'34281 BG57IV3@XCL T816588223 .K.F1994950968[T65,L612,R42,V717]
c++ timer 计时
//z 2014-06-19 17:18:49 L.195'24071 BG57IV3@XCL T1202481319.K.F636940351 [T22,L436,R14,V351]
//z 2014-06-20 14:28:39 L.194'34281 BG57IV3@XCL T816588223 .K.F1994950968[T65,L612,R42,V717]
class ZTimer
{
public:
ZTimer()//z is2120@BG57IV3
{
Init();
}
explicit ZTimer(const char* desc)
{
Init();
if (desc != NULL)
{
strcpy_s(_desc, desc);
}
}
void Reset()
{
++_resetCnt;
QueryPerformanceCounter(&_startCount);
}
double Elapsed()
{
return Elapsed(NULL);
}
double Elapsed(char* subDesc)
{
QueryPerformanceCounter(&_endCount);
double fElapsedTime = (_endCount.QuadPart - _startCount.QuadPart) * 1000.0 / _frequency.QuadPart;
char cBuff[256] = { 0 };
if (subDesc == NULL)
{
sprintf_s(cBuff, "Elapsed %s.T#%-2d.R#%-2d: %.3f", _desc, _cnt++, _resetCnt, fElapsedTime);
}
else
{
sprintf_s(cBuff, "Elapsed %s.%s T#%-2d.R#%-2d: %.3f", _desc,subDesc, _cnt++, _resetCnt, fElapsedTime);
}
OutputDebugStringA(cBuff);
return fElapsedTime;
}
~ZTimer()
{
Elapsed();
}
private:
void Init()
{
memset(_desc, 0, sizeof(_desc));
_startCount.QuadPart = 0;
_endCount.QuadPart = 0;
_cnt = 0;
_resetCnt = 0;
QueryPerformanceFrequency(&_frequency);
QueryPerformanceCounter(&_startCount);
}
private:
LARGE_INTEGER _frequency;
LARGE_INTEGER _startCount;
LARGE_INTEGER _endCount;
char _desc[64];
int _cnt;
int _resetCnt;
};
//z 2014-06-20 14:28:39 L.194'34281 BG57IV3@XCL T816588223 .K.F1994950968[T65,L612,R42,V717]