livewire Posted September 23, 2005 Share Posted September 23, 2005 I don't know if most of you know this, but newbees may benefit from this. Switch performs faster than If-ElseIf-Else and Select. -Livewire expandcollapse popup$repetitions = 1000000 $x = 10 $y = $repetitions $timestamp = TimerInit() While $y > 0 If $x = 0 Then ; Do nothing ElseIf $x = 1 Then ; Do nothing ElseIf $x = 2 Then ; Do nothing ElseIf $x = 3 Then ; Do nothing ElseIf $x = 4 Then ; Do nothing ElseIf $x = 5 Then ; Do nothing ElseIf $x = 6 Then ; Do nothing ElseIf $x = 7 Then ; Do nothing ElseIf $x = 8 Then ; Do nothing ElseIf $x = 9 Then ; Do nothing ElseIf $x = 10 Then $y -= 1 Else ; Do nothing EndIf WEnd $diff = "If-ElseIf-Else - " & TimerDiff($timestamp)/1000 & " seconds" & @CRLF $y = $repetitions $timestamp = TimerInit() While $y > 0 Select Case $x = 0 ; Do nothing Case $x = 1 ; Do nothing Case $x = 2 ; Do nothing Case $x = 3 ; Do nothing Case $x = 4 ; Do nothing Case $x = 5 ; Do nothing Case $x = 6 ; Do nothing Case $x = 7 ; Do nothing Case $x = 8 ; Do nothing Case $x = 9 ; Do nothing Case $x = 10 $y -= 1 Case Else ; Do nothing EndSelect WEnd $diff = $diff & "Select-Case - " & TimerDiff($timestamp)/1000 & " seconds" & @CRLF $y = $repetitions $timestamp = TimerInit() While $y > 0 Switch $x Case 0 ; Do nothing Case 1 ; Do nothing Case 2 ; Do nothing Case 3 ; Do nothing Case 4 ; Do nothing Case 5 ; Do nothing Case 6 ; Do nothing Case 7 ; Do nothing Case 8 ; Do nothing Case 9 ; Do nothing Case 10 $y -= 1 Case Else ; Do nothing EndSwitch WEnd $diff = $diff & "Switch-Case - " & TimerDiff($timestamp)/1000 & " seconds" MsgBox(0,"Done",$diff) Link to comment Share on other sites More sharing options...
w0uter Posted September 23, 2005 Share Posted September 23, 2005 also note that switch is smaller in text wich means a smaller file. My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll Link to comment Share on other sites More sharing options...
MSLx Fanboy Posted September 23, 2005 Share Posted September 23, 2005 That's a long execution time. Had to stop it and set it to 100,000 instead, took about a minute (23.5/22.5/14) Writing AutoIt scripts since _DateAdd("d", -2, _NowCalcDate()) Link to comment Share on other sites More sharing options...
w0uter Posted September 23, 2005 Share Posted September 23, 2005 just an FYI, put ProcessSetPriority(@AutoItPid, 5) at the top else your cpu time could get "stolen" in the middle of the test, thus making wrong conclusions. (also its faster ) My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll Link to comment Share on other sites More sharing options...
jefhal Posted September 23, 2005 Share Posted September 23, 2005 (edited) Switch performs faster than If-ElseIf-Else and Select.With release version of AutoIT I got:C:\Program Files\AutoIt3\Examples\TestOfSpeedSwitchCaseIFTHEN.au3 (69) : ==> "Case" statement with no matching "Select" statement.: Case 0Worked okay with beta 75.By the way, I take it that "$y -= 1" means decrement $y by one, but where do you find that nomenclature? Is there a place that spells out all of these special statements? Thanks... Edited September 23, 2005 by jefhal ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format Link to comment Share on other sites More sharing options...
w0uter Posted September 23, 2005 Share Posted September 23, 2005 (edited) With release version of AutoIT I got:Worked okay with beta 75.By the way, I take it that "$y -= 1" means decrement $y by one, but where do you find that nomenclature? Is there a place that spells out all of these special statements? Thanks...Switch = beta onlyHelpfile+= Addition assignment. e.g. $var += 1 (adds 1 to $var) -= Subtraction assignment. *= Multiplication assignment. /= Division assignment. &= Concatenation assignment. e.g. $var = "one", and then $var &= 10 ($var now equals "one10") Edited September 23, 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 Link to comment Share on other sites More sharing options...
Richard Robertson Posted September 24, 2005 Share Posted September 24, 2005 whats the point of select case AND switch? they do pretty much the same thing Link to comment Share on other sites More sharing options...
MSLx Fanboy Posted September 24, 2005 Share Posted September 24, 2005 Switch only analyzes the variable once, and allows for single-variable conditional statements. Writing AutoIt scripts since _DateAdd("d", -2, _NowCalcDate()) 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