#include <stdio.h>
#include <windows.h>
void main()
{
LARGE_INTEGER nFreq;
LARGE_INTEGER nBeginTime;
LARGE_INTEGER nEndTime;
double time;
QueryPerformanceFrequency(&nFreq);
QueryPerformanceCounter(&nBeginTime);
Sleep(1000);
QueryPerformanceCounter(&nEndTime);
time=(double)(nEndTime.QuadPart-nBeginTime.QuadPart)/(double)nFreq.QuadPart;
printf("%f
",time);
Sleep(1000);
system("Pause");
}
结果为
0.999982
1.000088
1.000200
等,所以Sleep的精度还是比较低的。