Sign in to follow this  
Followers 0
ZoltanE

How to decrease CPU overhead?

8 posts in this topic

Are there best practices to keep AutoIt scripts

easy on the CPU?

I'm on a Q6600@2.4Ghz with Win7 and my floating toolbar

script costs a constant 5-8%.

With a sleep(100) in the main loop it gets down

to 1-2%, but I read somewhere that a sleep is not

recommended there.

Share this post


Link to post
Share on other sites



Sleep is only not recommended when you are already using GUIGetMsg. If you aren't using that in the same loop, go ahead and add a sleep.

Share this post


Link to post
Share on other sites

Well, I am using GUIGetMsg().

So sleep makes the gui laggy... Hmm, I guess I'll have to

experiment with sleep times and see which value starts to cause

problems.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Zoltan, try replacing:

Toolbar_State()     ; Toggle "AlwaysOnTop" setting as required.
    Local $iMsg = GUIGetMsg() ; Check if an event has happened on the UI.

with

Local $iMsg = GUIGetMsg() ; Check if an event has happened on the UI.
    ; avoid unnecessary processing when no events ...
    If $iMsg = 0 Then ContinueLoop
    Toolbar_State()     ; Toggle "AlwaysOnTop" setting as required.

Of course this will only help if it actually is Toolbar_State() that eats your CPU :mellow:

edit: not tested, don't have PS

HTH,

whim

Edited by whim

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

whatever Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

When using sleep, have a delay of 15. This provides no noticeable lag, and drastically reduces CPU usage. This is the lowest time that Sleep can accurately delay for on all windows platforms.


_________[u]UDFs[/u]_________-Mouse UDF-Math UDF-Misc Constants-Uninstaller Shell

Share this post


Link to post
Share on other sites

Thanks a bunch guys!

Share this post


Link to post
Share on other sites

Use onevent mode if you are truly serious about reducing CPU usage.

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  
Followers 0