Jump to content

Optimum sleep time


Achilles
 Share

Recommended Posts

Since I use GuiOnEvent mode I often have loops that look like this:

While 1 
Sleep(2000) 
WEnd
I was just wondering if there was a sleep time that would produce less CPU usage... I know lower sleep times cause high CPU usage but do large ones (such as 2000) change anything?
My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

Since I use GuiOnEvent mode I often have loops that look like this:

While 1 
Sleep(2000) 
WEnd
I was just wondering if there was a sleep time that would produce less CPU usage... I know lower sleep times cause high CPU usage but do large ones (such as 2000) change anything?
I actually tried tweaking the value and found Sleep(20) was enough to free up the CPU. Didn't see much improvement from going higher. Nothing to stop you from testing it yourself to see if it makes any difference. Post your results when you get 'em.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I actually tried tweaking the value and found Sleep(20) was enough to free up the CPU. Didn't see much improvement from going higher. Nothing to stop you from testing it yourself to see if it makes any difference. Post your results when you get 'em.

:)

Any idea how to test it?

I started to try by doing this:

While 1 
Sleep(10)
WEnd
But that already registered in the task manager as 0% CPU usage...
My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

Any idea how to test it?

I started to try by doing this:

While 1 
Sleep(10)
WEnd
But that already registered in the task manager as 0% CPU usage...
Try it like this, and then uncomment the sleep:

HotKeySet("{ESC}", "_Quit")
While 1
    ; Sleep(20)
WEnd
Func _Quit()
    Exit
EndFunc

Like I said before, longer times are not really necessary.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Since I use GuiOnEvent mode I often have loops that look like this:

While 1 
   Sleep(2000) 
   WEnd
I was just wondering if there was a sleep time that would produce less CPU usage... I know lower sleep times cause high CPU usage but do large ones (such as 2000) change anything?
I usually use at least a sleep(1000). You want it to be as long as possible if you aren't using the loop because you are using GUIOnEvent mode. The less the processor has to do, the better. Each time it loops it is using a miniscule amount of processing power, however, over time that can add up. Since it doesn't matter, just give the processor a break and let it take a nap. :)

- The Kandie Man ;-)

EDIT: Fixed typo

Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

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...