My god I was surprised when I found this function, it's frickin' awesome.
It allows you to sleep down to 100 nanoseconds!
UDF:
; #FUNCTION#;===============================================================================
;
; Name...........: _HighPrecisionSleep()
; Description ...: Sleeps down to 0.1 microseconds
; Syntax.........: _HighPrecisionSleep( $iMicroSeconds, $hDll=False)
; Parameters ....: $iMicroSeconds - Amount of microseconds to sleep
; $hDll - Can be supplied so the UDF doesn't have to re-open the dll all the time.
; Return values .: None
; Author ........: Andreas Karlsson (monoceres)
; Modified.......:
; Remarks .......: Even though this has high precision you need to take into consideration that it will take some time for autoit to call the function.
; Related .......:
; Link ..........;
; Example .......; No
;
;;==========================================================================================
Func _HighPrecisionSleep($iMicroSeconds,$hDll=False)
Local $hStruct, $bLoaded
If Not $hDll Then
$hDll=DllOpen("ntdll.dll")
$bLoaded=True
EndIf
$hStruct=DllStructCreate("int64 time;")
DllStructSetData($hStruct,"time",-1*($iMicroSeconds*10))
DllCall($hDll,"dword","ZwDelayExecution","int",0,"ptr",DllStructGetPtr($hStruct))
If $bLoaded Then DllClose($hDll)
EndFunc
No msdn link for this one, since there is none
Note: Even though it supports down to 100 ns sleep don't count on that for being correct in practise because autoit will take some time to call the function (and all the other sutff that are in the UDF). For example on my machine, it took autoit 260 microseconds to call the function.