Djordhan Posted April 1, 2011 Share Posted April 1, 2011 Hi there, Forgive my ignorance but does setting a variables before using increase processing time at runtime ? Ex: Is sample1 faster than sample2 at runtime ? Sample1: MsgBox(0,"Hello", "World") Sample2: $sTitle = "Hello" $sText = "World" MsgBox(0,$sTitle, $sText) Thank you. Link to comment Share on other sites More sharing options...
dufran3 Posted April 1, 2011 Share Posted April 1, 2011 (edited) If you change the script just slightly, you can test that. If you use MsgBox, it is hard to actually test because you are taking into account how long it takes to click ok. So I change them to this: ;Sample1: ConsoleWrite('Hello World') which takes 0.324s to run and this ;Sample 2 $sTitle = "Hello" $sText = "World" ConsoleWrite($sTitle & $sText) which takes 0.430s Edit:Scite has a built in timer that lets you see the time elapsed to complete the script. Note however that the times varied, and are not exactly the same each time. Edited April 1, 2011 by dufran3 Link to comment Share on other sites More sharing options...
Djordhan Posted April 1, 2011 Author Share Posted April 1, 2011 So setting variables before using them in function to enhance code readability and usability does in fact increase processing time ? I thought it was just compiling time. I'll take care not to overuse this then Thanks! Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted April 1, 2011 Share Posted April 1, 2011 There is no real compiling. AutoIt is interpreted, when you compile the script it's just basically pasted to a stub of the interpreter. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
ChrisL Posted April 2, 2011 Share Posted April 2, 2011 So setting variables before using them in function to enhance code readability and usability does in fact increase processing time ? I thought it was just compiling time. I'll take care not to overuse this then Thanks!This is quite ridiculous.You could declare thousands of variables in less time than it takes to blink, declare all you like..In fact use Opt("MustDeclareVars",1) at the top of your script to force you in to declaring them when you use variables and create functions it is much better and safer to declare local Variables in functions. [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
Djordhan Posted April 2, 2011 Author Share Posted April 2, 2011 Sorry to sound ridiculous.. I was talking about those times when you assign value to a variable only for better readability, instead of using the value directly in function.I always declare my variables before using them.But I agree that saving a split second doesn't really matter.I'll take care not to overuse this thenThis was more like if I have a script that runs thousands of sql queries and the script is ran thousands of time overnight. The difference could became more than a split second if I set a variable for each query string before passing it to the function. Link to comment Share on other sites More sharing options...
GEOSoft Posted April 2, 2011 Share Posted April 2, 2011 You can always re-use a variable as well and that is really what you should always attempt to do. When you are finished with it the first time then give it a new value. Local $sFile = @DeskTopDir & "\Test.txt" Local $sTxt = "SomeText" FileWriteLine($sFile, $sTxt) $sTxt = "More text" ; here we re-use $sTxt FileWrite($sFile, $sTxt) George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
ChrisL Posted April 2, 2011 Share Posted April 2, 2011 Sorry to sound ridiculous.. I was talking about those times when you assign value to a variable only for better readability, instead of using the value directly in function.I always declare my variables before using them.But I agree that saving a split second doesn't really matter.This was more like if I have a script that runs thousands of sql queries and the script is ran thousands of time overnight. The difference could became more than a split second if I set a variable for each query string before passing it to the function.I will quite often use a variable to hold a long string, particularly with an SQL query, I find that it is easer to spot mistakes and make changes, they don't need to be in a variable but it does make it more readable and easier to spot the mistakes. It's also good if your spreading the data over multiple lines to chuck it in a variable. [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire 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