BOOL QueryPerformanceCounter(
__out LARGE_INTEGER *lpPerformanceCount
);
LARGE_IN
TEGER startTimer()
{
LARGE_INTEGER start;
DWORD_PTR oldmask = SetThreadAffinityMask(GetCurrentThread(), 0);
QueryPerformanceCounter(&start);
SetThreadAffinityMask(GetCurrentThread(), oldmask);
return
start;
}
LARGE_INTEGER endTimer()
{
LARGE_INTE
GER stop;
DWORD_PTR oldmask = SetThreadAffinityMask(GetCurrentThread(), 0);
QueryPerformanceCounter(&stop);
SetThreadAffinityMask(GetCurrentThread(), oldmask);
return
stop;
}
我正在使用这些功能,但我不确定它返回值的类型。 endTimer - startTimer =?如何将此结果转换为秒?
答案 0 :(得分:1)
您需要获得频率并将它除以2个计数器差异。
LARGE_INTEGER fr,t1,t2;
QueryPerformanceCounter(&t1);
// some lengthy code ...
QueryPerformanceCounter(&t2);
QueryPerformanceFrequency(&fr);
double diff_sec = (t2.QuadPart-t1.QuadPart)/(double)fr.QuadPart;