Tight Loops - Giving Back to the Processor

Tight loops consume CPU cycles. A tight loop that doesn't yield to the processor will hog the processor and can prevent other processes getting the CPU and can therefore slow down your system. Consider this simple loop:

Let>x=1
Label>start
  Let>x=x+1
Goto>start

Run that and you'll notice CPU utilisation for Macro Scheduler will jump up to around 99%. Now force the loop to yield to the processor with a tiny Wait statement:

Let>x=1
Label>start
  Let>x=x+1
  Wait>0.05
Goto>start

The difference is dramatic. CPU utilisation in Task Manager will now be next to zero.

The Wait statement delays the current process (the script) and allows other processes to get resource. It is basically allowing the processor to time slice. Without it the processor never gets a chance to do anything else.

So, always add a small Wait statement into a tight loop. If your loop doesn't already perform any kind of Wait then add Wait>0.05 and it will improve performance immensely.

Still need help? Contact Us Contact Us