Jump to content

WHY a while loop speedup when the mouse is moving


Recommended Posts

Searching inside the forum, I don't succeed to get any explanation about a strange (for me !) phenomena:

Using AutoIt, I have coded a "cortex of neurons Simulator" for which I handle several neurons activity (Action Potential and Postsynaptic Potential) which take a long time, about 20 ms per neuron to be processed. This is why I need a global loop running about 1s for a global cortex of 50 neurons.

But when I move the mouse (in any direction, like rotating above the GUI) the speed of the loop increase significantly : around x8 times more ... !

This happens only if the GUI has the focus. I did a check with the "Windows Task Manager" where I can see the CPU usage changing every time the mouse is moving (growing from 3% to 15%).

I believe to remember some lecture about the influence of the user events regarding the "Application" capability to anticipate user actions by changing it's rate of pooling events, but I'm not sure it was in an AutoIt forum, or maybe it was in an other "developer forum" (like "Code Project", "Stackoverflow" , or ...?

Could somebody help me to understand this behaviour ?

If possible, is there a programmatic method to manage the speed of a simple "For, Next" loop ? I try to change the Application priority (setting to level 4 with "ProcessSetPriority"), but this seems not very efficient ....

Thanks, Alain.


FYI: I'm using :

  • Autoit 3.3.14.2
  • Windows 7 Home Premium Service Pack 1
  • Computer ASUS N56V
  • Screen resolution: 1920x1080 (recommended)
  • Theme :Windows Classic
Link to comment
Share on other sites

You're probably using GUIGetMsg, that function has a built in sleep when nothing is going on with the GUI, when you're moving the mouse over it or actioning a control the delay is bypassed.

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!

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

Link to comment
Share on other sites

Thanks for this precision about GUIGetMsg.

The "Remarks" in the AutoIt help indicates something different, No ? : ".... This function automatically idles the CPU when required so that it can be safely used in tight loops without hogging all the CPU. ...."

--> Should it be ?  : ".... This function automatically idles the GUI polling cycle when required so that it can be safely used in tight loops without hogging all the CPU. ...."

Subsequent question: to avoid such "built in sleep" behaviour, could I use the function "GUICtrlSetOnEvent", that means using the option "GUIOnEventMode" set to 1 ?

Alain.

 

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

×
×
  • Create New...