JRowe Posted June 11, 2008 Share Posted June 11, 2008 Is Switch faster than Select or If/Elseif, since it's only testing one value against multiple conditions, or is it all in memory anyway and there's no difference between the two? I ask because I'm going to have large arrays (5000+ elements) being tested frequently, and I want to rewrite this function to be as fast as AutoItly possible. I'm also fairly certain the amount of code in this function could be pared down with StringRegExp. Func __ArraySearchWithWildcards ($array, $searchstring) If Not IsArray ($array) Then Return -2 For $z = 0 To UBound ($array) - 1 $string_split = StringSplit (StringStripWS ($array[$z], 3), "*") If $string_split[0] = 1 And StringInStr (StringStripWS ($searchstring, 3), $string_split[1]) Then If StringReplace (StringStripWS ($searchstring, 3), $string_split[1], "") = "" Then Return $z EndIf ElseIf $string_split[0] = 2 Then If StringInStr (StringStripWS ($searchstring, 3), $string_split[1]) And _ StringInStr (StringStripWS($searchstring, 3), $string_split[2]) Then Return $z EndIf If $string_split[1] = "" And StringInStr (StringStripWS($searchstring, 3), $string_split[2]) Then Return $z EndIf If $string_split[2] = "" And StringInStr (StringStripWS($searchstring, 3), $string_split[1]) Then Return $z EndIf EndIf Next Return -1 EndFunc [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center] Link to comment Share on other sites More sharing options...
d4rk Posted June 11, 2008 Share Posted June 11, 2008 if you work on 1 variable, use Switch , but in your case, i think Select will be better than if/ [quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys Link to comment Share on other sites More sharing options...
JRowe Posted June 11, 2008 Author Share Posted June 11, 2008 (edited) Func __ArraySearchWithWildcards ($array, $searchstring, $z=0) If Not IsArray ($array) Then Return -2 While $z< UBound($array)-1 $string_split = StringSplit (StringStripWS ($array[$z], 3), "*") Select Case $string_split[0] = 1 And StringInStr (StringStripWS ($searchstring, 3), $string_split[1]) If StringReplace (StringStripWS ($searchstring, 3), $string_split[1], "") = "" Then Return $z EndIf Case $string_split[0] = 2 Select Case StringInStr (StringStripWS ($searchstring, 3), $string_split[1]) And StringInStr (StringStripWS($searchstring, 3), $string_split[2]) Return $z Case $string_split[1] = "" And StringInStr (StringStripWS($searchstring, 3), $string_split[2]) Return $z Case $string_split[2] = "" And StringInStr (StringStripWS($searchstring, 3), $string_split[1]) Return $z EndSelect EndSelect $z+=1 WEnd Return -1 EndFunc That seems to be what I wanted. Works like a charm, and I personally think it's more elegant than all the If/EndIfs. Now for the stringRegExp experimentation Thanks! Edited June 11, 2008 by Jrowe [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center] Link to comment Share on other sites More sharing options...
weaponx Posted June 11, 2008 Share Posted June 11, 2008 There are some benchmarks for a few of the control structures here:http://www.autoitscript.com/forum/index.ph...mp;hl=benchmarkhttp://www.autoitscript.com/forum/index.ph...mp;hl=benchmarkMy own topic about AutoIt function overhead:http://www.autoitscript.com/forum/index.ph...ction++overhead Link to comment Share on other sites More sharing options...
JRowe Posted June 11, 2008 Author Share Posted June 11, 2008 Neat. I can implement my own benchmarks now that I've got those examples to work with... hadn't thought of that Thanks! [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center] 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