65,209
社区成员
发帖
与我相关
我的任务
分享
#include <cstdio>
#include <Windows.h>
int main()
{
LARGE_INTEGER freq, start, end;
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&start);
Sleep(10000); // 10 sec
QueryPerformanceCounter(&end);
printf("%f sec\n", (end.QuadPart - start.QuadPart)*1.0/freq.QuadPart);
return 0;
}
//10.014788 sec
下面是MSDN里的描述
QueryPerformanceFrequency
The QueryPerformanceFrequency function retrieves the frequency of the high-resolution performance counter, if one exists. The frequency cannot change while the system is running.
BOOL QueryPerformanceFrequency(
LARGE_INTEGER *lpFrequency // current frequency
);
Parameters
lpFrequency
[out] Pointer to a variable that receives the current performance-counter frequency, in counts per second. If the installed hardware does not support a high-resolution performance counter, this parameter can be zero.
Return Values
If the installed hardware supports a high-resolution performance counter, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError. For example, if the installed hardware does not support a high-resolution performance counter, the function fails.
QueryPerformanceFrequency
The QueryPerformanceFrequency function retrieves the frequency of the high-resolution performance counter, if one exists.
BOOL QueryPerformanceFrequency(
LARGE_INTEGER *lpFrequency // address of current frequency
);
Parameters
lpFrequency
Pointer to a variable that the function sets, in counts per second, to the current performance-counter frequency. If the installed hardware does not support a high-resolution performance counter, this parameter can be to zero.
Return Values
If the installed hardware supports a high-resolution performance counter, the return value is nonzero.
If the installed hardware does not support a high-resolution performance counter, the return value is zero.
QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in winbase.h.
Import Library: Use kernel32.lib.
See Also