Celeri Posted August 21, 2005 Posted August 21, 2005 (edited) I'm really disappointed by my latest project. My initial versions were really quick but my latest ones just CRAWL So I set up this little program to test the speed of different commands in AutoIT. It isn't pretty but I think the logic is there. It tests a specific function 1000 times, 15 times in a row and then averages the results. It also copies the average to the clipboard so you can paste it in excel or AutoIT (remove the semicolon on line 25 if you want to paste in Excel) Anyways, what I really wanted to know is how For/Next, Do/Until and While/Wend compared. I've pasted the results within the code for my program. (And I've run the program 5 times just to be sure eheheh) expandcollapse popup; Speed Test 1.00 ; Standard 1000 iterations for each command ; Repeat each 1000 iterations 15 times and calculate average ; Copy value to clipboard to paste here or in another program #include<array.au3> Dim $Stat[16] $Total = 0 For $a = 1 to 15 $i = 0 $Start = TimerInit() ; ==== CODE STARTS HERE For $i = 1 to 1000 Next ; ==== CODE ENDS HERE $End = TimerDiff($Start) $Stat[$a] = $End Next _ArrayDisplay($Stat,"TimerDiff") For $i = 1 to Ubound($Stat)-1 $Total=$Total+$Stat[$i] Next MsgBox(1,"Average",$Total/(Ubound($Stat)-1)) ClipPut("; "&$Total/(Ubound($Stat)-1)&@CR) Exit ; For/Next THE WINNER! ; 7.57139979276093 ; 7.79678943795334 ; 7.93297816843535 ; 7.68593630376008 ; 7.67898507640452 ; Do/Until ; 14.9826625695263 ; 14.9933205178595 ; 14.6738275151559 ; 15.0026756946678 ; 14.966137730613 ; While/Wend ; 19.7842360381606 ; 19.3168873881921 ; 19.6748217386644 ; 19.7558880432582 ; 19.7558880432582 ; If/EndIf THE WINNER! ; 0.0220238920451162 ; 0.0221127666416551 ; 0.0219136742058813 ; 0.0218826598063387 ; 0.0221396124391086 ; Select/EndSelect ; 0.0221819654363335 ; 0.0232866449899358 ; 0.02282909922464 ; 0.0245067114493634 ; 0.0224139064565691 ; Compared commands ; Loops types ; For/Next For $i = 1 to 1000 Next ; Do/Until Do $i=$i+1 Until $i=999 ; While/Wend While $i < 999 $i=$i+1 WEnd ; If/Then types ; If/Then If 1 Then EndIf ; Select/EndSelect Select Case 1 EndSelect Notice how For/Next loops simply dominate the two other loops? It seems clear (at least to me) that AutoIT3 looses a lot of time with "$i = $i +1" and that translates in really poor performance. It gets even worse with While/Wend because the loop checks if a variable is smaller than 999 (I assume = is faster to process than <). So what's the moral of the story? There's a few ways of writing the same stuff in AutoIT3. Not all of them give quick results. Please note, the values I got are NOT from compiled code and my PC is a P4 2800Mhz 800Mhz FSB, 512Mb Ram Dual-Channel (Asus P4P800 SE / Intel 865Pe chipset). Hope this comes in handy Edited August 21, 2005 by Celeri I am endeavoring, ma'am, to construct a mnemonic circuit using stone knives and bearskins.SpockMy UDFs:Deleted - they were old and I'm lazy ... :)My utilities:Comment stripperPolicy lister 1.07AutoIT Speed Tester (new!)
Celeri Posted August 21, 2005 Author Posted August 21, 2005 Here's the values for the compiled version of this program ... (using the following lines:) ; ==== CODE STARTS HERE For $i = 1 to 1000 Next ; ==== CODE ENDS HERE ; 4.90730872667072 ; 4.90685701694834 ; 5.15343650027989 ; 4.93482150045855 ; 4.91766653565346 And now values for the following lines: ; ==== CODE STARTS HERE Do $i=$i+1 Until $i=999 ; ==== CODE ENDS HERE ; 11.4218521694596 ; 11.5570175915008 ; 11.7162947082574 ; 11.520992365503 ; 11.5550718547897 So For/Next is still I am endeavoring, ma'am, to construct a mnemonic circuit using stone knives and bearskins.SpockMy UDFs:Deleted - they were old and I'm lazy ... :)My utilities:Comment stripperPolicy lister 1.07AutoIT Speed Tester (new!)
LxP Posted August 21, 2005 Posted August 21, 2005 It interests me that your compiled script yields faster results than an uncompiled copy, since a 'compiled script' is really just an AutoIt executable 'stub' with an encoded form of the original script found at the end.I suppose that the differences in speed are due to the compiled executable's AutoIt stub not having to parse human-readable tokens into AutoIt-usable bytecode. Nonetheless, I would have thought that an uncompiled AutoIt script would be completely translated to bytecode before execution of it were to start and not on a line-by-line basis (the results shown above suggest otherwise).Perhaps it does though, with the speed differences being caused by other factors.
Celeri Posted August 21, 2005 Author Posted August 21, 2005 I suppose that the differences in speed are due to the compiled executable's AutoIt stub not having to parse human-readable tokens into AutoIt-usable bytecode. Nonetheless, I would have thought that an uncompiled AutoIt script would be completely translated to bytecode before execution of it were to start and not on a line-by-line basis (the results shown above suggest otherwise).<{POST_SNAPBACK}>Yep, I was a bit surprised too By the way tried to see if using Hex values made any difference in speed with regular numbers. It made the loop even slower! (showing that using Hex numbers probably ADD to the processing each time they're handled)Which is kind of sad; perhaps AutoIT4 will enable the user to configure a variable to be of a certain type (bolean, floating point, etc. etc. etc.) with the economy in speed when precision is not needed ... Oh well BTW I am grateful, AutoIT is a lot of fun to program - anyways my wife hates it so it must be doing something good I am endeavoring, ma'am, to construct a mnemonic circuit using stone knives and bearskins.SpockMy UDFs:Deleted - they were old and I'm lazy ... :)My utilities:Comment stripperPolicy lister 1.07AutoIT Speed Tester (new!)
Celeri Posted August 21, 2005 Author Posted August 21, 2005 A bit more info ... I've compared two similar forced loops: While 1 $Fichier = FileFindNextFile($Recherche) If @error Then ExitLoop Wend and Do $Fichier = FileFindNextFile($Recherche) If @error Then ExitLoop Until 0 Note that a previous search was started BEFORE THE LOOP with FileFindFirstFile Now I've never seen anyone use Do/Until 0 but trust me, it does exactly the same thing. It loops forever Here are the results (in miliseconds, repeated 5 times to reduce statistical errors): ; While/Wend ; 61.762602327271 ; 61.9402332987935 ; 61.8511987946785 ; 61.8864561641715 ; 61.9275730875049 ; Do/Until ; 46.7085407748836 ; 46.5693268064935 ; 46.72530339086 ; 46.6055034361192 ; 46.5999905432284 As you can see, there's a clear 15Ms between the two variations! At this moment I'm wondering why there is such a discrepancy. There should be little difference between both variations. Anyways, I've modified all my While/Wend loops .... I am endeavoring, ma'am, to construct a mnemonic circuit using stone knives and bearskins.SpockMy UDFs:Deleted - they were old and I'm lazy ... :)My utilities:Comment stripperPolicy lister 1.07AutoIT Speed Tester (new!)
w0uter Posted August 21, 2005 Posted August 21, 2005 (edited) you could use While NOT @error. Edited August 21, 2005 by w0uter My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll
Celeri Posted August 21, 2005 Author Posted August 21, 2005 you could use While NOT @error.<{POST_SNAPBACK}>I've taught of that (thanks anyways!)My problem is that the error flag will be overwritten as soon as you add material to the loop. So by the time you get to "While NOT @error", it's not checking for the same error And loading the next file at the end of the procedure is not very efficient Oh btw I don't know why but in my previous test the For/Next loop gave me wrong results. Testing it again puts back For/Next on top, with a large margin:For $i = 1 to 1000 $Fichier = FileFindNextFile($Recherche) If @error Then ExitLoop NextResults (in miliseconds, repeated 5 times to reduce statistical errors):; 27.5826528983695; 27.6469020616715; 27.5852736151308; 27.5871114684199; 27.5142494729696So it's clear. Until something is done about Do/Until and While/Wend, anyone making time-critical loops should stick to For/Next.Too bad, Do/Until and While/Wend really make a program easy to read. I am endeavoring, ma'am, to construct a mnemonic circuit using stone knives and bearskins.SpockMy UDFs:Deleted - they were old and I'm lazy ... :)My utilities:Comment stripperPolicy lister 1.07AutoIT Speed Tester (new!)
Uten Posted September 21, 2005 Posted September 21, 2005 So it's clear. Until something is done about Do/Until and While/Wend, anyone making time-critical loops should stick to For/Next.Too bad, Do/Until and While/Wend really make a program easy to read.This is not so strange. In a For/Next loop autoit knows how many itterations to do upfront. This is not the case with a Do/Until While/Wend loop. Also in your Do/Until While/Wend loops autoit has to do "real work" namely $i=$i+1And sa a last note. When testing like this, Im my opinion, each test should run in it's own process. Aka. One test -> one script/program. When isolated like this startup, interpreter, compilation or what ever should not affect the result (on a unloaded machine).RegardsUten Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling
w0uter Posted September 22, 2005 Posted September 22, 2005 also just an FYI, [$i+=1] is faster then [$i=$i+1] My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll
Celeri Posted October 18, 2005 Author Posted October 18, 2005 (edited) also just an FYI,[$i+=1] is faster then [$i=$i+1]WOW ... this is GREAT!EDIT: Works only on beta versions ...Although the "wording" is a bit weird... I did try [$i==+1] --> Syntax error I might also try my speed test on the latest beta version (just for kicks). This might seem strange but I had a real tough time getting the betas to work ... I must be stooopid or something Edited October 18, 2005 by Celeri I am endeavoring, ma'am, to construct a mnemonic circuit using stone knives and bearskins.SpockMy UDFs:Deleted - they were old and I'm lazy ... :)My utilities:Comment stripperPolicy lister 1.07AutoIT Speed Tester (new!)
MSLx Fanboy Posted October 18, 2005 Posted October 18, 2005 The += is a C-style operator that just adds the number to the variable, instead of getting the value, adding to it, and setting the variable to the new value. Example1: You think of a number. Add 2 to the number. Example2: You think of a number. Tell me the number. I add 2 to the number, I tell you the new number. Which is faster? Writing AutoIt scripts since _DateAdd("d", -2, _NowCalcDate())
gamerman2360 Posted December 2, 2005 Posted December 2, 2005 (edited) While 1 $Fichier = FileFindNextFile($Recherche) If @error Then ExitLoop WendWould "While True" make it faster so it dosn't have to see if 1 is true everytime or does it have to evaluate if true is true? ---------- This is not so strange. In a For/Next loop autoit knows how many itterations to do upfront.But if it knew then when you change the variable in the for loop it wouldnt change how many times it would loop. for $i = 1 to 7 $i = 2 NextWould still be a loop of 7 ------- [edit] Oooo... Mabey For $i = 1 To 7 $i = 2 NextIs a faster While 1 WEnd Edited December 2, 2005 by gamerman2360
PartyPooper Posted December 2, 2005 Posted December 2, 2005 also just an FYI, [$i+=1] is faster then [$i=$i+1] Didn't seem to want to work for me using latest beta and scite (Au3Check complained). Instead of: Do $x = $x + 1 ... Until 0 I tried: Do $x+ = 1 ... Until 0 Is this the correct syntax or am I doing something wrong?
gamerman2360 Posted December 2, 2005 Posted December 2, 2005 Have you tried saving it and running the script by itself? I think scite has its function names set to the stable one, it can be switched, however, if you look at some of scite's files. Anyway if it is set to the stable definations then the check will have errors.
PartyPooper Posted December 2, 2005 Posted December 2, 2005 No, I didn't think to run it outside of sciTE because I assumed Au3Check to be correct in that it was a syntax error. I'll try it tonight. Thanks for the heads up. Not sure about switching in sciTE, but I normally run scripts as beta. To be honest, sciTE has so many tools and options that it just confuses me so I tend to manually type in the code and only use ALT-T and ALT-F5.
Zedna Posted December 2, 2005 Posted December 2, 2005 (edited) Do $x+ = 1 ... Until 0 Is this the correct syntax or am I doing something wrong? This is right: Do $x += 1 ... Until 0 Download latest beta and look into Help file... Edited December 2, 2005 by Zedna Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search
gamerman2360 Posted December 2, 2005 Posted December 2, 2005 (edited) So it works now? I wasn't that sure if scite specified which version of Autoit, lol. I know there is a way to update the definations, for my the updater is here: "C:\Program Files\AutoIt3\SciTe\Defs" Edited December 2, 2005 by gamerman2360
gamerman2360 Posted December 2, 2005 Posted December 2, 2005 This is right: Do $x += 1 ... Until 0Ah, never really used it till now... Cool.
PartyPooper Posted December 2, 2005 Posted December 2, 2005 Cool, $x += 1 works without syntax error popping up. Thanks Zedna
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