Continuous loops max out my CPU usage. What can I do?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Kwhiz
Junior Coder
Posts: 35
Joined: Wed Jan 12, 2005 6:19 pm

Continuous loops max out my CPU usage. What can I do?

Post by Kwhiz » Mon Nov 14, 2005 5:58 pm

Hi,

If I run a continuous loop in my script, such as

label>start
gpc>50,50,x
if>x=0,end
goto>start
label>end

my CPU runs at 100% usage. That's way too high for me to run this script throughout the day. I guess this is a two-part question. The first part of the question is this: Is there a CPU fast enough to handle a continuous-loop script without maxing out at 100% CPU usage? I currently have a 3.2GHz machine with 1GB RAM, which seems very fast to me under most circumstances, yet a continuous-loop script maxes out my machine.

Part two of the question is this: If there is no CPU fast enough yet to run continous-loop scripts, does anybody have any thoughts or ideas regarding workarounds to the above script? I'm just using the above script as an example of course. Any continous-loop script will fit under the category of this thread.

Thanks!
Kwhiz

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Mon Nov 14, 2005 6:11 pm

This comes up often. Any tight loop in any programming language will consume CPU cycles. Put a small wait inside the loop to ensure each iteration can yield to the processor:

label>start
Wait>0.5
gpc>50,50,x
if>x=0,end
goto>start
label>end
MJT Net Support
[email protected]

Kwhiz
Junior Coder
Posts: 35
Joined: Wed Jan 12, 2005 6:19 pm

Post by Kwhiz » Mon Nov 14, 2005 6:51 pm

.
Wow, that's fabulous. Even Wait>0.001 works! Although Wait>0.0003 doesn't work.

Thank you for your time, help and understanding.

-- Kwhiz

Hardware_Tester
Pro Scripter
Posts: 58
Joined: Mon Jun 27, 2005 7:03 am
Location: Switzerland

Post by Hardware_Tester » Tue Nov 15, 2005 1:25 pm

Who wonders, on a 2GHz Machine, while a wait of 0.001 2 Million of basic operations can be calculated.

Kwhiz
Junior Coder
Posts: 35
Joined: Wed Jan 12, 2005 6:19 pm

Post by Kwhiz » Fri Nov 18, 2005 2:50 pm

lol.

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts