Jump to content

Recommended Posts

Posted

@TheAutomator the following script takes about 10ms to run, because of the Sleep(10) instruction so the condition is checked only twice. Also, there is no value from Sleep(1) to Sleep(9) in AutoIt, the minimum is Sleep(10) ms

Local $i = 0, $hTimer = TimerInit()

While $i < 1
    $i += 1
     Sleep(10)
WEnd

ConsoleWrite(Int(TimerDiff($htimer)) & " ms" & "   i = " & $i & @crlf)

Now, without the Sleep(10) instruction, you'll need (at least) the following equivalent code to run in 10ms :

Local $i = 0, $hTimer = TimerInit()

While $i < 5000
    $i += 1
WEnd

ConsoleWrite(Int(TimerDiff($htimer)) & " ms" & "   i = " & $i & @crlf)

The condition will have to be checked 5000 times (or 10.000 or more, depending on your computer speed) to exit the loop in 10ms, then CPU heats up.

So the condition was checked only twice in the 1st example and 5.000+ times in the 2nd example, that's a big difference in 10ms !

On 4/20/2022 at 11:40 PM, TheAutomator said:

(read somewhere that sleep even does tiny sleeps with breaks to check for hotkey-presses)

Yes, but those tiny sleeps are all = 10ms (not less when AutoIt Sleep is used) which means that Sleep(100) will call ten times this function :

DllCall("Kernel32.dll", "none", "Sleep", "dword", 10)

Some interesting links below :
https://www.autoitscript.com/forum/topic/93496-tutorial-on-dllcall-dllstructs/?do=findComment&comment=698697

https://www.autoitscript.com/forum/topic/177648-sleep-problem/?do=findComment&comment=1275022

https://www.autoitscript.com/forum/topic/143520-sleep-less-than-1/

https://github.com/ellysh/au3src/blob/master/src/utility.cpp
Check for the word sleep :

2030        // Set the minimum Sleep accuracy
2031        if (g_oVersion.IsWin9x())
2032            dwMin = 55;
2033        else
2034            dwMin = 10;


 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...