Jump to content

Reduce CPU Load


Recommended Posts

Hi All,

i always used the following in my while/wend loop to reduce the amount op cpu usage the program uses.. when just displaying the GUI

but after the last release this option will not reduce the cpu load anymore.. has something changed or is this not the correct way

Switch $msg
   Case - 3
      ExitLoop
   Case - 100 To 0
     ContinueLoop
EndSwitch

Thnx

Emiel

Edited by Emiel Wieldraaijer

Best regards,Emiel Wieldraaijer

Link to comment
Share on other sites

Where is the full loop's code? Are you using GUIGetMsg() in the loop? Are you using OnEventMode? Not enough info to say here but looks like you did a cheesy fix that relied logic overhead to slow the loop down. The newer versions are more optimized so I guess this doesn't slow them down as much anymore. Can't really say though because like I said we don't have enough information.

- The Kandie Man ;-)

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

@The Kandie Man

$traymsg = TrayGetMsg()
$msg = GUIGetMsg()
  Switch $msg
    Case - 3
      ExitLoop
   Case - 100 To 0
     ContinueLoop
 EndSwitch
 Select
  Case $msg = 0
    ; and the rest

@weaponx

i don't like this option .. because the buttons will respond slower

Edited by Emiel Wieldraaijer

Best regards,Emiel Wieldraaijer

Link to comment
Share on other sites

@The Kandie Man

$traymsg = TrayGetMsg()
$msg = GUIGetMsg()
  Switch $msg
    Case - 3
      ExitLoop
   Case - 100 To 0
     ContinueLoop
 EndSwitch
 Select
  Case $msg = 0
    ; and the rest

@weaponx

i don't like this option .. because the buttons will respond slower

What are you trying to do with all these Switches and Case statements? I don't see you using control id variables to detect if any buttons are pressed with those case statements. Can you show your entire script so that we may understand what it is that the script is doing?

- 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

I just use a sleep(10) in all indefinite loops, reduces cpu load by a good 90%. And i don't think they'll notice a ~10 ms delay.

My two cents.

EDIT: after smoke's post, just wanted to point out i don't just mean this for GUI loops, i mean 'most any WHILE 1 or while true etc loop.

~cdkid

Edited by cdkid
AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!
Link to comment
Share on other sites

  • Moderators

I just use a sleep(10) in all indefinite loops, reduces cpu load by a good 90%. And i don't think they'll notice a ~10 ms delay.

My two cents.

~cdkid

GUIGetMsg() is all you need, you won't see any difference in CPU usage if you've coded correctly.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Developers

I just use a sleep(10) in all indefinite loops, reduces cpu load by a good 90%. And i don't think they'll notice a ~10 ms delay.

My two cents.

~cdkid

GUIGetMsg() already has a "built-in"10 ms delay.

Better not put an extra sleep() in the loop because that could cause GUI's not responding....

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

Link to comment
Share on other sites

You are correct Jos i noticed it also..

but with 3.2.5.0 with the following code in the While/Wend loop

$traymsg = TrayGetMsg()

$msg = GUIGetMsg()

The next line causes the CPU usage when added for different languages

[EDIT]

If BitAND(_IsPressed("12"), _IsPressed("58")) And WinActive("GUIName") And $Language = "UK" Then Terminate()

If BitAND(_IsPressed("12"), _IsPressed("58")) And WinActive("GUIName") And $Language = "EN" Then Terminate()

[/edit]

Switch $msg

Case - 3

ExitLoop

Case - 100 To 0

ContinueLoop

EndSwitch

Select

Case $msg = 0

; and the rest

will reduce the CPU load of the GUI more info http://www.autoitscript.com/forum/index.ph...9&hl=Switch

Edited by Emiel Wieldraaijer

Best regards,Emiel Wieldraaijer

Link to comment
Share on other sites

Run your GUI in GuiOnEventMode. Your script can get all kinds of useful work done, and not be tied to the GuiGetMsg() loop.

:)

Edit: Cheap keyboard can't spell worth a darn...

Edited by PsaltyDS
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

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