Celeri Posted August 19, 2007 Share Posted August 19, 2007 (edited) Well maybe it's me (it surely is) but I like my AutoIT code when it's FAST.So here's a little program I whipped up in about an hour.AutoIT_Speed.au3Updated 19Aug2007 with more comments and more test resultsIt will execute commands of your choice through two loops, 20 packs of 9999 iterations to be precise. Making two loops increased the reliability of the reading (since it seems the first iteration is really slow because of cache issues and what not).For example, you could compare $Val = $Val +1to ...$Val += 1(in this case, the obvious winner is $Val += 1 but it isn't always so evident)The code is as simple as can be, I guess if you don't get it than it's not for you In any case, the results you get might make you change your programming habits!If you do a lot of looping then I suggest you try out the commands in those loops and see what's better. Good luck!EDIT:It's been brought to my attention by chris95219 that GetTickCount() cannot be properly timed. Also if you use the $i and $j variables in your code (both loop counters) you will obviously get incorrect results!TESTED BY YOURS TRUELY:1. For/Next loops are champions. Try not to use While/Wend or Do/Until2. If $Val is faster than If $Val = 1 or $Val = TRUE3. If $Val = 1 is faster than $Val = TRUE4. If Not $Val is faster than If $Val = 0 or $Val = FALSE5. If $Val = 0 is faster than If $Val = FALSE6. < and > are faster than =, >= or <= (Wow!)7. $i += 1 is faster than $i = $i + 1 $i -= 1 is faster than $i = $i - 1 $i *= 1 is faster than $i = $i * 1 $i /= 1 is faster than $i = $i / 18. If doing a lot of verifications on a single variable:Switch is fastest, Select is second (but slow) and If is slowest.9. If $Val is a string, If Not $Val is faster than If $Val = ""If $Val is faster than If $Val <> ""10. When doing binary operations, If $Val -128 > 0 is twice as fastas If BitAnd($Val, 128).11. Using Hex numbers is faster than using decimal numbers12 Replacing dec/hex numbers by variables slows down execution. Use hex/dec numbers when possible13. Longer variable names = longer execution time. Keep variable names short and clear!14. StringRegExpReplace() is slower than StringReplace(). Use it only if necessary!15. StringRegExp() is slower than StringInStr(). Use only if necessary!16. Opt("ExpandEnvStrings",1) makes $Val = "%TEMP%" faster than $Val = EnvGet("temp") or $Val = @TempDir17. $Val = @TempDir is faster than $Val = EnvGet("temp")18. Opt("ExpandVarStrings",1) makes $Val = "$String$" slightly faster than $Val = $String19. However $Val = "@TempDir@" is slower than $Val = @TempDir (go figure!) Edited August 21, 2007 by Celeri argumentum, Cahkhene25 and BBs19 3 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!) Link to comment Share on other sites More sharing options...
cppman Posted August 19, 2007 Share Posted August 19, 2007 Nice test... (but these results would be inaccurate if AutoIt uses GetTickCount() internally for it's Timer functions...) Miva OS Project Link to comment Share on other sites More sharing options...
Celeri Posted August 19, 2007 Author Share Posted August 19, 2007 Nice test... (but these results would be inaccurate if AutoIt uses GetTickCount() internally for it's Timer functions...) Wow, I've never used GetTickCount() I'll add a line to the first post just in case BTW there are other functions that can't really be tested by my program. There's "Exit" (duh!) and "Return". I guess you could call a function and return but you can never test "Return" all alone. Which makes me think ... Hmmm what's fastest? SetError($ErrNum) Return Or Return SetError($ErrNum) 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!) Link to comment Share on other sites More sharing options...
Celeri Posted August 19, 2007 Author Share Posted August 19, 2007 (edited) SetError($ErrNum)<BR>Return Or Return SetError($ErrNum) On my computer Return SetError($ErrNum) is marginally slower than SetError($ErrNum) Return But by so little that there's nothing to write home about Edited August 19, 2007 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!) Link to comment Share on other sites More sharing options...
cppman Posted August 19, 2007 Share Posted August 19, 2007 It would be pretty cool if you used an input box or 'load file' to let the user choose the file/expression to test it's speed Miva OS Project Link to comment Share on other sites More sharing options...
Sunaj Posted August 19, 2007 Share Posted August 19, 2007 (edited) Hi Celeri, thanks for sharing your experiments here, there has been a few other threads dealing with the differing performance of various AutoIt loops and operators - still you added quite a few subtle ones I haven't come across before ("If Not $Val" being faster than "If $Val = 0" for an example).SunajEDIT: Interesting thing here is that learning these basic tricks of the trade is a rather good idea since they hold true (on some level at least) not just for AutoIt but also for Java, C++ and more (see: http://www.codeproject.com/cpp/C___Code_Optimization.asp and http://www.javaworld.com/javaworld/jw-04-1...ze.html?page=1)TESTED BY YOURS TRUELY:1. For/next loops are champions. Try not to use While/Wend or Do/Until2. If $Val is faster than If $Val = 1 or $Val = TRUE3. If $Val = 1 is faster than $Val = TRUE4. If Not $Val is faster than If $Val = 0 or $Val = FALSE5. If $Val = 0 is faster than If $Val = FALSE6. < and > are faster than =, >= or <= (Wow!)7. $i += 1 is faster than $i = $i + 18. If doing a lot of verifications on a single variable: Switch is fastest, Select is second (but slow) and If is slowest. Edited August 19, 2007 by Sunaj [list=1][*]Generic way to detect full path to default browser, List/ListView Events Using GuiRegisterMsg (detect doubleclick and much more)[*]Using dllcall for full control over fileopendialog, Make DirMove act somewhat normally (by circumventing it...)[*]Avoid problems with "&" (chr(38)) in code, Change desktop maximized area/workspace (fx to make deskbar type app)[*]Change focus behavior when buttons are clicked to work closer to 'standard windows' app[*](Context) Menus With Timed Tooltips, Fast Loops & Operators in AU3[*]Clipboard UDF, A clipboard change notification udf[/list] Link to comment Share on other sites More sharing options...
Celeri Posted August 19, 2007 Author Share Posted August 19, 2007 (edited) It would be pretty cool if you used an input box or 'load file' to let the user choose the file/expression to test it's speed I'll see what I can do However this might require a thinking cap! --> it implies a self-modifying code. But I'm all for it if it is possible. One way this could be done is by #including a file which contains bunch of UDFs to be speedtested. The user would then have to specify which UDF to speed test. (i.e.: _speedtest1() ) EDIT: In retrospect, it can be done with Execute() but since you're going to have to code it anyways, an input box or an input file is in my opinion not the best way to go. Don't forget this program tests code snippets that sometimes requires preset variables and/or calling parameters, which is way beyond Execute() (I was lead to believe it is used to return the result of a simple expression like 1 + $B [the function returns the equal part of the formula and $B in this case must be previously declared]). In any case if it's what you want it's easy to add two lines to the code: Put this at the start: $Input_CODE = InputBox("AutoIT Speed Test","Enter command to test it's speed"&@CR&"(One line only!)") Put this line at line after the "For $j = 1 To 9999" and the comments that follow $Result = Execute($Input_CODE) You can ConsoleWrite the variable $Result after the loops if you want to see what happened. There are also issues with syntax checking but if it's used by someone who knows his stuff than I guess it's OK. In any case I commented every line so that unexperimented users can take a peek and understand how this works. If any of you modifies the code (make it faster?) than I'd really appreciate seeing what you did Edited August 19, 2007 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!) Link to comment Share on other sites More sharing options...
Celeri Posted August 19, 2007 Author Share Posted August 19, 2007 Hi Celeri, thanks for sharing your experiments here, there has been a few other threads dealing with the differing performance of various AutoIt loops and operators - still you added quite a few subtle ones I haven't come across before ("If Not $Val" being faster than "If $Val = 0" for an example).EDIT: Interesting thing here is that learning these basic tricks of the trade is a rather good idea since they hold true (on some level at least) not just for AutoIt but also for Java, C++Thanks! I started learning C++ but I'm lazy and I have a limited amount of time. AutoIt's learning curve is really, really low Although there's a few quirks here and there but you get used to it.I'll keep on comparing - if any of you has anything interesting, post it and I'll add it to the first post 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!) Link to comment Share on other sites More sharing options...
laffo16 Posted August 20, 2007 Share Posted August 20, 2007 i would like to see differences in speed/performance between autoit & c# at handling large _arrays (sorting and searching). Link to comment Share on other sites More sharing options...
Celeri Posted August 20, 2007 Author Share Posted August 20, 2007 i would like to see differences in speed/performance between autoit & c# at handling large _arrays (sorting and searching).Since AutoIt is an interpreted language (as compared to a compiled language) the difference will probably pretty big (not in favor of AutoIT3). Hey anyone here can prove me wrong? 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!) Link to comment Share on other sites More sharing options...
cppman Posted August 21, 2007 Share Posted August 21, 2007 (edited) Since AutoIt is an interpreted language (as compared to a compiled language) the difference will probably pretty big (not in favor of AutoIT3). Hey anyone here can prove me wrong?Probably not (Your Right) C# is much much much faster than AutoIt. In fact C# is probably about 90% the speed of C++. Edited August 21, 2007 by chris95219 Miva OS Project Link to comment Share on other sites More sharing options...
Celeri Posted August 21, 2007 Author Share Posted August 21, 2007 (edited) Probably not (Your Right) C# is much much much faster than AutoIt. In fact C# is probably about 90% the speed of C++.Mind you, it depends.If you're working with files and file transfers in AutoIT3, the difference in speed with C# or C++ will be minimal since the program will be dependent upon Harddrive latency. I once made a cleaning program in AutoIT3 and it was up there with CCleaner in terms of speed Edited August 21, 2007 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!) Link to comment Share on other sites More sharing options...
cppman Posted August 21, 2007 Share Posted August 21, 2007 The thing is, you have to remember what AutoIt is doing behind the scenes. Your AutoIt program is being overlayed on a C++ program. $x = TimerInit() for $i = 0 to 1000 random(0, 65535) Next $y = TimerDiff($x) MsgBox(0, "", $y) This is taking anywhere from 9 to 60 ms on my computer - that is very slow. Whereas you can do that in C# or C++ in much much less time. Miva OS Project Link to comment Share on other sites More sharing options...
Celeri Posted August 21, 2007 Author Share Posted August 21, 2007 The thing is, you have to remember what AutoIt is doing behind the scenes. Your AutoIt program is being overlayed on a C++ program. $x = TimerInit() for $i = 0 to 1000 random(0, 65535) Next $y = TimerDiff($x) MsgBox(0, "", $y) This is taking anywhere from 9 to 60 ms on my computer - that is very slow. Whereas you can do that in C# or C++ in much much less time. That much is clear However my mom can program AutoIT3, but I doubt she'd get along with C++ or C# ahahahah 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!) Link to comment Share on other sites More sharing options...
Celeri Posted August 29, 2007 Author Share Posted August 29, 2007 (edited) That much is clear However my mom can program AutoIT3, but I doubt she'd get along with C++ or C# ahahahahOk so it looks I'm going to have to reply to myself to get any input here So anyways, just discovered 3.2.6.0 is out and it boasts a 30%-40% speed increase ... we'll be the judge of that <LI>Changed: General performance improvements (currently around 30-40% over 3.2.4.9)Download the new version here:http://www.autoitscript.com/forum/index.php?showtopic=51967I'll keep you posted with some observations in the following days.See ya! Edited August 29, 2007 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!) Link to comment Share on other sites More sharing options...
sandman Posted August 29, 2007 Share Posted August 29, 2007 (edited) I think this is a really good idea for testing AutoIt's limits. This will help a lot of people! Edited August 29, 2007 by sandman [center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center] Link to comment Share on other sites More sharing options...
Celeri Posted August 30, 2007 Author Share Posted August 30, 2007 (edited) Tested and so far it's true - 3.2.6.0 is very much FASTER. I suggest you upgrade and test again P.S.: Thanks for the encouragement Sandman Where do I apply for the toaster? Edited August 30, 2007 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!) Link to comment Share on other sites More sharing options...
Qwerty212 Posted March 18, 2012 Share Posted March 18, 2012 1. For/next loops are champions. Try not to use While/Wend or Do/Until But how can we change a While statement like when you want to get gui msg like this one: While 1 $msg = GUIGetMsg() Select Case $msg = $Button1 Func1() Endselect Wend and subtitute it for a For/Next ??? Link to comment Share on other sites More sharing options...
Shaggi Posted March 18, 2012 Share Posted March 18, 2012 But how can we change a While statement like when you want to get gui msg like this one: While 1 $msg = GUIGetMsg() Select Case $msg = $Button1 Func1() Endselect Wend and subtitute it for a For/Next ??? You shouldn't worry about that. A msgloop doesn't run that often for a change to be significant. @OP Autoit doesn't use getickcount, but queryperformancecounter, last time i checked, which is high-resolution and ok for testing. Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG Link to comment Share on other sites More sharing options...
BrewManNH Posted March 18, 2012 Share Posted March 18, 2012 @OPAutoit doesn't use getickcount, but queryperformancecounter, last time i checked, which is high-resolution and ok for testing.I don't think the OP will be too concerned, he hasn't been online in nearly 3 years, as this is a 5 year old topic brought back from the dead. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
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