Jump to content

Strange CPU scaling, efficiency matters....


OiMunk
 Share

Recommended Posts

Some of my scripts push the limits, so I started experimenting with distributing the sleep() command in different ways. I discovered that

sleep(5)+sleep(5)

does not equal sleep(10)

here's the test, I'd be interested in why this is, and if the CPU gains are real or illusory:

while 1 ;this uses 25% CPU

for $i = 1 to 20

$title=WinGetTitle("","")

$PID=WinGetProcess($title,"")

$a=pixelsearch(5,5,33,1000,4123645,44)

next

sleep(5)

sleep(5)

WEnd

And this uses 30%CPU....

while 1

for $i = 1 to 20

$title=WinGetTitle("","")

$PID=WinGetProcess($title,"")

$a=pixelsearch(5,5,33,1000,4123645,44)

next

sleep(10)

WEnd

Link to comment
Share on other sites

Anything between 0-10 will automatically be 10, so running sleep(5) two times will be equal to sleep(10) two times.

Try this and you will see what I mean

$Timer = TimerInit()
Sleep(1)
MsgBox(0, "", TimerDiff($Timer) & " ms went by")

$Timer = TimerInit()
Sleep(10)
MsgBox(0, "", TimerDiff($Timer) & " ms went by")
Edited by AdmiralAlkex
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...