miniopterus Posted February 5, 2018 Posted February 5, 2018 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.
Andreik Posted February 5, 2018 Posted February 5, 2018 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.
RTFC Posted February 5, 2018 Posted February 5, 2018 (edited) 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 February 5, 2018 by RTFC wrong example My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O
Imp Posted February 5, 2018 Posted February 5, 2018 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
RTFC Posted February 5, 2018 Posted February 5, 2018 @Imp: You are totally correct; must have been still asleep. Thanks for spotting that. And welcome to the forums. My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O
Zedna Posted February 5, 2018 Posted February 5, 2018 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. Resources UDF ResourcesEx UDF AutoIt Forum Search
miniopterus Posted February 6, 2018 Author Posted February 6, 2018 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now