Jump to content
miniopterus

Loop causes exe to slow to a crawl

Recommended Posts

miniopterus

Hi,

I have a video analysis .exe that tracks and counts objects. I have written a short AUTOIT script to run this based on a few inputs. Works great. But, I would like to loop through a range of inputs so the whole process can be automated rather than running the script step by step.  There are four variables, each one has 1-5 values. Looping through all combinations of these variables typically involves 60-240 steps.

When I have tried to run it through a loop (using arrays) each step of the video analysis takes about 20-30 minutes to run, instead of 2-3 minutes when I do it without using a loop.  Is this a memory clagging issue? It also makes no difference if I run it within 4 nested loops (1 loop per variable) or just one loop. 

I read something on this forum about a UDF that clears memory. Could this be the solution to my problem?

My looping code looks something like this:

 

Local $threshold[] = [12,13,14,15]

Local $losscount[] = [2,3,4]

 

For $Nthreshold in $threshold

   For $Nlosscount in $losscount

       ;each combination of $Nthreshold x Nlosscount gets used by the software

       ;and do video processing here

   Next

Next

So, in this example there are 4x3 = 12 steps to loop through. Does it matter that I have not declared Nthreshold and Nlosscount before using them in the looping process?

 

Many thanks.

 

Share this post


Link to post
Share on other sites
Andreik

It's a known fact that AutoIt loops are pretty slow but 240 loops shouldn't be a problem and your script definitely should not last for 30 minutes. I think the main consuming time it's your video processing. If you can show us more from your code we can point out where is the latency.


When the words fail... music speaks

Share this post


Link to post
Share on other sites
RTFC

Regardless of what your loops do, you can reduce slowdown in looping by using explicit iterators (For $var=0 to <maxvalue>) instead of For-In constructs. The following snippet shows the difference (on my machine the second test is abour 3x as fast, both compiled and interpreted):

Local $test
Local $array1[234]
Local $array2[567]

Local $tstart=TimerInit()
For $rc In $array1
    For $cc In $array2
        $test=$rc*$cc
    Next
Next
Local $tdiff1=TimerDiff($tstart)

Local $rcmax=UBound($array1)-1
Local $ccmax=UBound($array2)-1

Local $tstart=TimerInit()
For $rc=0 To $rcmax
    For $cc=0 To $ccmax
        $test=$rc*$cc
    Next
Next
Local $tdiff2=timerdiff($tstart)
MsgBox(0,"ForIn vs ForIterator","Duration For with In: " & $tdiff1 & @CRLF & "Duration For with Iterator: " & $tdiff2 & @CRLF)

EDIT: this example is completely wrong, as was pointed out below. Please ignore.

Edited by RTFC
wrong example

Share this post


Link to post
Share on other sites
Imp

Wrong sample.

You use unitialized arrays. Every elements of its is a empty string.

In first loop you attempt to multiply strings with explicit conversion to number. This take a time.

In second loop you multiply integer indexes without(!) any access to arrays.

Functionally  equalent statement for second loop should be $test=$array1[$rc]*$array2[$cc] Try to change this line and see different results. Moreover, if you initialize arrays with numbers, then first loop wins!

----------------

Sorry for my bad English

Share this post


Link to post
Share on other sites
Zedna

Try to disable your antivirus, it may check your EXE at each iteration of your loop before executing this EXE.

Just thought ...

Also post what you do inside your loop as I don\t think loops are source of problem.

Share this post


Link to post
Share on other sites
miniopterus

Awesome! Many thanks to all who replied. I tried explicit iterators (For-to) instead of the "For-in" as suggested by RTFC and modified by Imp and it made a massive difference! I can now iterate through each step and combination of variables in a fraction of the time.

Share this post


Link to post
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

×