Jump to content
Sign in to follow this  
JRowe

Conditionals question

Recommended Posts

JRowe

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

Share this post


Link to post
Share on other sites
d4rk

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

Share this post


Link to post
Share on other sites
JRowe

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 by Jrowe

Share this post


Link to post
Share on other sites
JRowe

Neat. I can implement my own benchmarks now that I've got those examples to work with... hadn't thought of that :)

Thanks!

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×