Thanks. "timeBeginPeriod" is exactly what I needed.
It also shows that AutoIt's sleep() function is indeed hardcoded to go as low as 10ms.
Here's a new code example:
$hDll_ntdll = DllOpen("ntdll.dll")
$hDll_winmm = DllOpen("winmm.dll")
$rounds = 500
$resolution = 0
$result1 = _test(); tests for and shows the standard timer resolution
MsgBox(0, "test 1", "Example for standard timer resolution" & @CRLF & @CRLF & "total: " & $result1 & @CRLF & "average: " & $result1 / $rounds)
$result2 = _test(1); sets timer resolution to 1ms and performs test
MsgBox(0, "test 1", "Example for 1ms timer resolution" & @CRLF & @CRLF & "total: " & $result2 & @CRLF & "average: " & $result2 / $rounds)
$result1 = _test(); to show that the timer resolution was successfully reset
MsgBox(0, "test 1", "Example for standard timer resolution" & @CRLF & @CRLF & "total: " & $result1 & @CRLF & "average: " & $result1 / $rounds)
Func _Test($highPrecision = 0)
Sleep(1000)
$begin = TimerInit()
For $i = 1 To $rounds
_HPSleep(1, 1, $highPrecision)
Next
$dif = TimerDiff($begin)
Return ($dif)
EndFunc ;==>_Test
Func _HPSleep($iSleep, $fMs = 1, $highPrecision = 0)
; default is milliseconds, otherwise microseconds (1 ms = 1000 µs)
If $fMs Then $iSleep *= 1000 ; convert to ms
if $highPrecision > 0 Then DllCall($hDll_winmm, "int", "timeBeginPeriod", "int", $highPrecision)
DllCall($hDll_ntdll, "dword", "NtDelayExecution", "int", 0, "int64*", -10 * $iSleep)
if $highPrecision > 0 Then DllCall($hDll_winmm, "int", "timeEndPeriod", "int", $highPrecision)
EndFunc ;==>_HPSleep
A word of caution, directly from Microsoft, http://msdn.microsoft.com/en-us/library/windows/desktop/dd757624(v=vs.85).aspx