Jump to content
Sign in to follow this  
OiMunk

Strange CPU scaling, efficiency matters....

Recommended Posts

OiMunk

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

Share this post


Link to post
Share on other sites
qazwsx

sleep was changed after a certain version and sleeps which are 10 or greater are different from other ones. I think i remember reading that anyway. Also calling sleep twice probably takes longer than calling it once.

Share this post


Link to post
Share on other sites
AdmiralAlkex

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

Share this post


Link to post
Share on other sites
OiMunk

Great, it finally makes sense...

They should mention that in the help file,

cheers,

OiM

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.