QueryPerformanceFrequency()函数获得机器内部计时器的时钟频率。
接着在需要严格计时的事件发生前和发生之后分别调用QueryPerformanceCounter(),利用两次获得的计 数之差和时钟频率,就可以计算出事件经历的精确时间。
_LARGE_INTEGER time_start; //结束时间 _LARGE_INTEGER time_over; //计时器频率 double dqFreq; //计时器频率 LARGE_INTEGER f; QueryPerformanceFrequency(&f); dqFreq=(double)f.QuadPart; QueryPerformanceCounter(&time_start); //循环耗时 Sleep(1000); QueryPerformanceCounter(&time_over); //单位为秒,精度为1000 000/(cpu主频)微秒 cout<<((time_over.QuadPart-time_start.QuadPart)/dqFreq)<