Jump to content

Recommended Posts

Posted

Hi all

everything that i put in the while loop in a non GUI script is making the CPU usage over 25 %

if i used _ispressed or hotkeyset or string funcs or pretty much everything except sleep() is making it 25%

for example try this  "

#include <Misc.au3>
$dll = DllOpen("user32.dll")
While 1
If _IsPressed("0D", $dll) Then enter()
WEnd
func enter()
    msgbox(0, "", "enter")
EndFunc

this small script is making the CPU usage 31% 

this is happening not only on my PC 

how can i make CPU usage much less without using sleep ()    ?

cuz i have some scripts athe really 100 ms or less matters

thanks in advanced

  • Moderators
Posted

Alexxander,

Sleep(10) is what I use to keep tight loops from frying the CPU - if that short a pause causes you problems than you probably need to use another language. ;)

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:

  Reveal hidden contents

 

Posted

try to use GUIGetMsg()

 

description from helpfile:

"This function automatically idles the CPU when required so that it can be safely used in tight loops without hogging all the CPU."

and in:

GUI Reference - MessageLoop Mode 

"Usually a tight loop like the one shown would send the CPU to 100% - fortunately the GUIGetMsg function automatically idles the CPU when there are no events waiting. Do not put a manual sleep in the loop for fear of stressing the CPU - this will only cause the GUI to become unresponsive."

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

As I mentioned the last time you said this, without a GUI GUIGetMsg is useless. Use a short sleep as suggested.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

  Reveal hidden contents

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted (edited)

sorry @BrewManNH

With all due respect, if you did the test?

Because i did tests
following two scripts
 
 
first script: a non-stop 50% of the CPU
#include <Misc.au3>
$dll = DllOpen("user32.dll")
While 1
    If _IsPressed("0D", $dll) Then enter()
WEnd
Func enter()
    MsgBox(0, "", "enter")
EndFunc   ;==>enter
 
second script: max 1% of the CPU
#include <Misc.au3>
$dll = DllOpen("user32.dll")
While 1
    If _IsPressed("0D", $dll) Then enter()
    GUIGetMsg()
WEnd
Func enter()
    MsgBox(0, "", "enter")
EndFunc   ;==>enter
 

AutoIt 3.3.8.1
OS Name Microsoft Windows 7 Professional
Version 6.1.7601 Service Pack 1 Build 7601
Intel ® Core 2 Duo CPU P8700@2.53GHz, 2534 MHz, cores: 2 logical CPUs: 2

 
 
please test it on your system, and confirm or deny my findings
Edited by mlipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

I'm not saying it doesn't work, what I said was it was pointless to use the function like that. There's no GUI so no need to use GUIGetMsg when a simple Sleep does the same thing. Why over-complicate things by using a function incorrectly, when there's a function that is purpose-built to do it?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

  Reveal hidden contents

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted
  On 9/25/2013 at 8:13 PM, mlipok said:

 

sorry @BrewManNH

With all due respect, if you did the test?

Because i did tests
following two scripts
 
 
first script: a non-stop 50% of the CPU
#include <Misc.au3>
$dll = DllOpen("user32.dll")
While 1
    If _IsPressed("0D", $dll) Then enter()
WEnd
Func enter()
    MsgBox(0, "", "enter")
EndFunc   ;==>enter
 
second script: max 1% of the CPU
#include <Misc.au3>
$dll = DllOpen("user32.dll")
While 1
    If _IsPressed("0D", $dll) Then enter()
    GUIGetMsg()
WEnd
Func enter()
    MsgBox(0, "", "enter")
EndFunc   ;==>enter
 

AutoIt 3.3.8.1
OS Name Microsoft Windows 7 Professional
Version 6.1.7601 Service Pack 1 Build 7601
Intel ® Core 2 Duo CPU P8700@2.53GHz, 2534 MHz, cores: 2 logical CPUs: 2

 
 
please test it on your system, and confirm or deny my findings

 

 

Yes when i put GUIGetMsg() in  my script the CPU usage decreased from  30%  to 4%

but i still find it too much for a super small script

i can't understand why mr.

BrewManNH

 

keep finding it "useless" or "pointless"

anyways thanks a lot 

mlipok

Posted
  On 9/25/2013 at 8:22 PM, BrewManNH said:

There's no GUI so no need to use GUIGetMsg when a simple Sleep does the same thing.

 

if you do not using:

#AutoIt3Wrapper_Change2CUI=y

then

AutoIt always create GUI

see in 

AutoItWinSetTitle Beta HelpFile

#include <GUIConstantsEx.au3>

Example()

Func Example()
    ; Set the title of of the AutoIt Hidden Window.
    AutoItWinSetTitle("My AutoIt Window")

    ; Display AutoIt's Hidden Window.
    AutoItWinShow()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>Example

; Display AutoIt"s Hidden Window. Returns the handle of the window.
Func AutoItWinShow()
    Local $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window.
    WinMove($hWnd, "", (@DesktopWidth / 2) - 250, (@DesktopHeight / 2) - 250, 500, 500) ; Move the AutoIt Hidden Window and re-size for a better view.
    WinSetState($hWnd, "", @SW_SHOW) ; Show the AutoIt Hidden Window, normally this is hidden, but in the interest of this example I"m displaying it.
    Return $hWnd
EndFunc   ;==>AutoItWinShow

So there is a GUI, but mostly about him does not remember.

At least, I think that about this.
If anyone has other thoughts, then I be happy to take them.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Moderators
Posted (edited)

And a sleep(10) will reduce it the same. I don't know how lousy a CPU you have, but it took 29% on mine without the sleep. Adding the sleep took it down to 3%.

@mlipok - just because by some chance GUIGetMsg works in this case doesn't mean using a GUI function in a non-GUI script is good coding practice. If you're going to "help" forum users, you should be suggesting the right tool for the job. Why complicate matters when a simple sleep will work?

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

  • Developers
Posted (edited)

@mlipok,

Using GUIGetMsg() is not the correct advice and is confusing. You should use sleep(xx) in stead as suggested by BrewManNH and JLogan3o13.

The fact that AutoIt3 creates a hidden GUI doesn't bare any relation to using GUIGetMsg().

 

  On 9/25/2013 at 8:23 PM, Alexxander said:

 

Yes when i put GUIGetMsg() in  my script the CPU usage decreased from  30%  to 4%

but i still find it too much for a super small script

i can't understand why mr.

BrewManNH

 

keep finding it "useless" or "pointless"

anyways thanks a lot 

mlipok

 

 

You clearly haven't understood anything suggested by BrewManNH and JLogan3o13 so maybe you should read it again before making these dumb statements. ;)

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

  • Moderators
Posted

I have to admit credit goes to BrewManNH for (properly) suggesting Sleep in both this and the previous topic. I just had to add my 2 cents as to how dumb it is suggesting the wrong tool :)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

  • Moderators
Posted

mlipok,

I entirely agree with JLogan3o13 - there is no point in using GUIGetMsg unless you are looking to get a return from the message system about an actioned control as it is purely by chance that there is a built-in delay within the function to prevent the CPU getting overheated. If there is no GUI being used by a MessageLoop mode script itself then there is no point in suggesting that people use the GUIGetMsg function rather than the function designed to pause the script. The fact that there is always a hidden Autoit GUI has nothing to do with anything - that is a just requirement of AutoIt to access the system.

Using GUIGetMsg to reduce CPU load in any other form of script is only going to confuse. Think about an OnEvent script - would you suggest using GUIGetMsg inside its idle loop? Of course not - you would suggest Sleep. So please do not continue with this approach which risks the opposite of what we should aim to do - clarify AutoIt coding for those who seek help here. :)

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:

  Reveal hidden contents

 

Posted (edited)
All right.
 
I took all the attention, to my knowledge.
 
I'll try to think about it thoroughly.
Of course, I no longer suggest such solutions.
 
Though it is possible that at some unspecified time in the distant future, I will ask a more precise question, of course, in a separate thread.
I hope that edit: if not in this case, not offended at me, just as I hope not offended now.
 
Greetings to all and I apologize for putting confusion.
Edited by mlipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Moderators
Posted

mlipok,

 

  Quote

Though it is possible that at some unspecified time in the distant future, I will ask a more precise question, of course, in a separate thread

Please do. :)

 

  Quote

I hope that in this case, not offended at me, just as I hope not offended now

No-one should feel offended - all we are trying to do is make sure that the best advice is given to those seeking help here. ;)

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:

  Reveal hidden contents

 

  • 4 years later...
Posted

This thread is nearly 5 years old. Don’t necro old threads just to say ‘thks’ ;) 

My UDFs and Tutorials:

  Reveal hidden contents

 

  • Moderators
Posted
  On 8/24/2018 at 12:56 AM, diehardfans said:

guigetmsg() is the key, thks

Expand  

Not only did you resurrect a very old post, but you completely missed the point of it. Please read through it again, and please refrain from bringing old posts back to life, especially when you are adding nothing to the conversation.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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
  • Recently Browsing   0 members

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