在网上找了很久试了很久,感觉这个是最好的,拿出来分享下。
BOOL QueryPerformanceFrequency(LARGE_INTEGER *lpFrequency);
返回硬件支持的高精度计数器的频率。
BOOL QueryPerformanceCounter (LARGE_INTEGER *lpCount); //获得的计数。
LARGE_INTEGER是union;用于表示一64位有符号整数值.其他定义如下:
typedef union _LARGE_INTEGER {
struct {
DWORD LowPart;
LONG HighPart;
};
LONGLONG QuadPart;
} LARGE_INTEGER;
正确过程如下。
LARGE_INTEGER start;
LARGE_INTEGER finish;
LARGE_INTEGER frequency;
QueryPerformanceFrequency(&frequency);
QueryPerformanceCounter(&start);
test();
QueryPerformanceCounter(&finish);
cout<<double(finish.QuadPart-start.QuadPart)/frequency.QuadPa