Busti Posted June 2, 2006 Share Posted June 2, 2006 (edited) 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 ?! expandcollapse popupDim $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 2.78974003679239 ; _MyStringReverse() 18.0880530905464 ; _StringReverse() €Dit: 3.3 ms ;my 12.02 ms ;std Edited June 2, 2006 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 More sharing options...
tittoproject Posted June 2, 2006 Share Posted June 2, 2006 Hi, I tried your script and for each test the results was different! Mostly _MyStringReverse() was faster than _StringReverse(), but sometime no! Link to comment Share on other sites More sharing options...
Busti Posted June 2, 2006 Author Share Posted June 2, 2006 (edited) 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 June 2, 2006 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 More sharing options...
mr.underperson Posted June 2, 2006 Share Posted June 2, 2006 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!-mups.. 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 More sharing options...
Busti Posted June 2, 2006 Author Share Posted June 2, 2006 (edited) 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 June 2, 2006 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 More sharing options...
JSThePatriot Posted June 2, 2006 Share Posted June 2, 2006 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 More sharing options...
Busti Posted June 2, 2006 Author Share Posted June 2, 2006 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 More sharing options...
JSThePatriot Posted June 2, 2006 Share Posted June 2, 2006 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 More sharing options...
mr.underperson Posted June 2, 2006 Share Posted June 2, 2006 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 More sharing options...
Busti Posted June 2, 2006 Author Share Posted June 2, 2006 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 More sharing options...
JSThePatriot Posted June 2, 2006 Share Posted June 2, 2006 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?-muWell 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 More sharing options...
ptrex Posted June 2, 2006 Share Posted June 2, 2006 The same goes for.+=Happy scripting !! Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New 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