Jump to content

speed test : _MyStringReverse vs. _StringReverse


Busti
 Share

Recommended Posts

hi all, i've got a question, most of you know _stringreverse,

i wrote my own, becouse i found it too late, now i made a speed test,

but my reverse is only 8 lines, and _StringReverse is 14 lines long.... and i dont understand why my programm needs about ~0,2ms more ?!

Dim $SaveTimer[3]
Global Const $_String = "hello this is a real big test and i hope it will be reversed right !! by both functions :D"

$Timer1 = TimerInit()
$_MyReverse = _MyStringReverse($_String) 
$SaveTimer[1] = TimerDiff($Timer1)
TimerStop($Timer1)

$Timer2 = TimerInit()
$_StringReverse = _StringReverse($_String)
$SaveTimer[2] = TimerDiff($Timer2)
TimerStop($Timer2)

$SaveTimer[1] = Round($SaveTimer[1],2) & " ms"
$SaveTimer[2] = Round($SaveTimer[2],2) & " ms"
ClipPut( $SaveTimer[1] & @CRLF & $SaveTimer[2] )
MsgBox( 0, "",  "_MyStringReverse:  " & $_MyReverse & @CRLF & _
                "_StringReverse:    " & $_StringReverse & @CRLF & _
                "_MyStringReverse() took:   " & $SaveTimer[1] & @CRLF& _
                "_StringReverse()  took:    " & $SaveTimer[2] & @CRLF& _
                ($SaveTimer[2] - $SaveTimer[1]) * 100 &" %")
Exit

Func _MyStringReverse($_String)
    Local $Ret
    If StringLen($_String) < 1 Then Return ""
    For $i = 1 To StringLen($_String)
        $Ret &= StringRight(StringTrimRight($_String,$i-1),1)
    Next
    Return $Ret
EndFunc

Func _StringReverse($sString)
    Local $sReverse
    Local $iCount
    If StringLen($sString) >= 1 Then
        For $iCount = 1 To StringLen($sString)
            $sReverse = StringMid($sString, $iCount, 1) & $sReverse
        Next
        Return $sReverse
    Else
        SetError(1)
        Return ""
    EndIf
EndFunc   ;==>_StringReverse

€dit : sorry now it works!!! mine is very much faster,

mine needs for this :

2.73386701382438

and _stringreverse :

18.2771832732931

but if i start it more times, its always variating ?!

why ?

€Dit : changed some of code now works 90% faster :D

2.78974003679239 ; _MyStringReverse()

18.0880530905464 ; _StringReverse()

€Dit:

3.3 ms ;my

12.02 ms ;std

Edited by Busti
My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity
Link to comment
Share on other sites

thx 4 reply, ive run it now about 100times and in 96 of 100 it was faster

2.66 ms

39.01 ms

3635 %

dramaticle speed increase?^^

if my math func is correct^^

standart - myfunction * 100

Edited by Busti
My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity
Link to comment
Share on other sites

Sheesh! If we had a buck for every time we wrote a faster version of a UDF, well, there would be enough for a decent slap-up meal, anyway.

Now, why not apply this programatical genius to something useful!

-mu

ps.. using the "&=" operator gives dramatic speed improvements to many tried-and-tested AutoIt function. Perhaps it is fairly new (the operator), which would explain why a lot of old AutoIt code screams to have it swapped-in.

Link to comment
Share on other sites

isn't it good to speed up a UDF ?

a udf uses 2min to create something,

you speed it up to 10 sec,

won't you be happy ?

i know its not very needet if 0.020 or 0.002

but its a change!

Edited by Busti
My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity
Link to comment
Share on other sites

Yes it is good that you have found a way to speed it up. Now get it in the same standard format and submit it as a replacement for the current. First I would make it 100% of the time faster, or atleast make a documented reason on why sometimes it isnt that way JdeB when he is doing the UDF's can decide whether or not to replace the current.

@mr.underperson

"&=" is relatively new. I do believe it's only available in the beta versions of AutoIt, and that is the exact reason it wouldnt be in any of the older UDF's.

Another thing about "&=" or any of those similiar operators, I had though Valik or someother such dev had mentioned that they might be a tad slower. I havent tested nor can I remember if this was actually said. I think it deserves some speed testing for sure.

IMHO,

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

here :

Func _StringReverse($_String)
    Local $Ret
    If StringLen($_String) < 1 Then Return ""
    For $i = 1 To StringLen($_String)
        $Ret &= StringRight(StringTrimRight($_String,$i-1),1)
    Next
    Return $Ret
EndFunc
My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity
Link to comment
Share on other sites

here :

Func _StringReverse($_String)
    Local $Ret
    If StringLen($_String) < 1 Then Return ""
    For $i = 1 To StringLen($_String)
        $Ret &= StringRight(StringTrimRight($_String,$i-1),1)
    Next
    Return $Ret
EndFunc
What do you mean? This isnt how you submit it. Goto the Scripts and Scraps forum at the top and goto the UDF thread. Read the first post on how to get a UDF ready for submission. Follow those guidelines. Then post in the thread and give the reason you are updating the current one. Refer to this thread.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Tad Slower? Nah, JS! Not the ones I've played with.

I recently improved my favourite recursion routine by around 15x (that's 1500% increase in speed) simple by swapping in the &= operator wherever it was applicable.

I'm used to doing it with php ".=", and when I tried it with AutoIt, it worked. But looking at a lot of snippets around the forum I see it's not there, so I figured it must be a fairly new addition.

Perhaps it's time for the UDF writers to review their old code.

By the way, Busti, what about error handling?

-mu

Link to comment
Share on other sites

how do you mean, wich error ?

the only 1 error i know in this script could be an empty string, but its fixxed with :

If StringLen($_String) < 1 Then Return ""

or do you mean when autoit crashes? hmm

My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity
Link to comment
Share on other sites

Tad Slower? Nah, JS! Not the ones I've played with.

I recently improved my favourite recursion routine by around 15x (that's 1500% increase in speed) simple by swapping in the &= operator wherever it was applicable.

I'm used to doing it with php ".=", and when I tried it with AutoIt, it worked. But looking at a lot of snippets around the forum I see it's not there, so I figured it must be a fairly new addition.

Perhaps it's time for the UDF writers to review their old code.

By the way, Busti, what about error handling?

-mu

Well I am happy to hear that. I have written a couple of UDF's I dont recall if I have updated them or not. I will certainly check into it.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...