Very simple, to get the current time prior to Sleep, and then get at the current time after Sleep, compare two time difference to know.
E.g
SYSTEMTIME tBeforeSleep;
GetSystemTime(&tBeforeSleep);
Sleep(2);
SYSTEMTIME tAfterSleep;
GetSystemTime(&tAfterSleep);
So I think even before Sleep (1), will be like Sleep (15) almost, might Sleep accuracy only to about 15 milliseconds, I recently discovered that this is wrong.
When Sleep (2), and the sleep time before the sleep or to the same, or to a difference of 10 milliseconds, because the accuracy is a function of acquisition time of 10 milliseconds, not Sleep () function problems.
In multimedia applications, there is a more accurate time function DWORD timeGetTime (), usage () is similar with GetTickCount, get the number of milliseconds to turn the current time. MSDN says that the function can be accurate to 5ms or more, depending on the speed of the machine. Further, with timeBeginPeriod and timeEndPeriod accuracy of the system provided function of time, so timeGetTime () has a higher degree of accuracy.
timeBeginPeriod(1);//设置系统精确到1秒
DWORD time1 = timeGetTime();
SYSTEMTIME sysTime1;
GetSystemTime(&sysTime1);
timeEndPeriod(1);//每个timeBeginPeriod对应一个timeEndPeriod取消提高精确度
Sleep(5);
timeBeginPeriod(1);
DWORD time2 = timeGetTime();
SYSTEMTIME sysTime2;
GetSystemTime(&sysTime2);
timeEndPeriod(1);
It was found that, Sleep function is quite accurate. timeGetTime function also,
However, the acquisition time is generally a function of the accuracy of GetSystemTime GetLocalTime GetTickCount the like is generally 10 milliseconds.