::GetTickCount误差18ms,所以不适合用于计算时间很短的程序,尤其是算法分析
#include <windows.h>
// 高精度计时器
class HpTimer
{
public:
HpTimer()
{
QueryPerformanceFrequency(&cpuFrequency);
}
void Start()
{
QueryPerformanceCounter(&start);
}
// 秒, 乘以1000就是毫秒
double Elapse()
{
LARGE_INTEGER end;
QueryPerformanceCounter(&end);
double elaspe;
elaspe = ((double)end.QuadPart - (double)start.QuadPart) / (double)cpuFrequency.QuadPart;
return elaspe;
}
private:
LARGE_INTEGER start;
LARGE_INTEGER cpuFrequency;
};