Jump to content

Sleep performance


James
 Share

Recommended Posts

So I'm just interested as to whether having a script which does the same as:

HotKeySet("{SPACE}", "ChangeSleep")

Dim $sleepTime = 500

While 1
    Sleep($sleepTime)
WEnd

Func ChangeSleep()
    If $sleepTime = 500 Then
        $sleepTime = 1000
    Else
        $sleepTime = 500
    EndIf
EndFunc
Would make much of a performance change? Is it worth changing the sleep to something a bit higher, if the script is just waiting?

-James

Link to comment
Share on other sites

  • Moderators

JamesBrooks,

As I understand it, in setting the Sleep period to those levels you would merely render the script less responsive in GetMessage mode and have no effect at all in OnEvent mode.

If I run a script with nothing more than an infinite loop containing Sleep(10) - which is the lowest you can go with the normal Sleep command - I get a very occasional "01" appearing on the Task Manager CPU monitor. The same is true for any of my running scripts which have a loop (GUIGetMsg injects its own idle time of ~12ms in GetMessage mode). So I do not believe that increasing the Sleep period would gain you much, if any, performance gain for other running apps - and you would definitely lose out if you were running in GetMessage mode because of the (lack of) response to actions within the script itself.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Well the script I'm concerned about doesn't have any OnEvent functions, so that's fine.

I'm just interested as to whether setting the scripts responsiveness to a higher level will help with performance.

Edit:

What I'm asking is; is there anything an application should be doing when it's just waiting for an event to occur (no GUI/Tray events)?

Edited by JamesBrooks
Link to comment
Share on other sites

  • Administrators

In GUIGetMsg mode the message loop automatically optimizes sleep so that when lots of events are firing it hardly sleeps and then when things quieten down it saves CPU and sleeps longer. Anything additional you do will more than likely make it worse ;)

Link to comment
Share on other sites

In GUIGetMsg mode the message loop automatically optimizes sleep so that when lots of events are firing it hardly sleeps and then when things quieten down it saves CPU and sleeps longer. Anything additional you do will more than likely make it worse ;)

Awesome, that's just what I was wondering! Thanks for your reply Jon!
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...