Zedna Posted May 3, 2012 Posted May 3, 2012 (edited) This function is very fast compared to standard _StringRepeat() when number of repeated chars is big.In my tests this version is faster than original for > 50 chars.Time needed for this new StringRepeat() is constant no matter how many chars you repeat (nCount)so for big numbers of repeated characters it's MUCH FASTER (hundred times).StringRepeat Function:Func StringRepeat($sChar, $nCount) $tBuffer = DLLStructCreate("char[" & $nCount & "]") DllCall("msvcrt.dll", "ptr:cdecl", "memset", "ptr", DLLStructGetPtr($tBuffer), "int", Asc($sChar), "int", $nCount) Return DLLStructGetData($tBuffer, 1) EndFuncTesting example for compare speed with standard _StringRepeat (try to change number of chars):#include <String.au3> $start = TimerInit() _StringRepeat('a',1000) ConsoleWrite(TimerDiff($start)& @CRLF) $start = TimerInit() StringRepeat('a',1000) ConsoleWrite(TimerDiff($start)& @CRLF) Func StringRepeat($sChar, $nCount) $tBuffer = DLLStructCreate("char[" & $nCount & "]") DllCall("msvcrt.dll", "ptr:cdecl", "memset", "ptr", DLLStructGetPtr($tBuffer), "int", Asc($sChar), "int", $nCount) Return DLLStructGetData($tBuffer, 1) EndFuncEDIT:There is one difference/limitation from original _StringRepeat(): This new StringRepeat() can repeat only one character, so it's not posiible to do: StringRepeat('abc',3) --> result is 'aaa'Maybe I should change its name from StringRepeat() to CharRepeat()EDIT2:Here is MemSet in form of UDF:Func MemSet($pDest, $nChar, $nCount) DllCall("msvcrt.dll", "ptr:cdecl", "memset", "ptr", $pDest, "int", $nChar, "int", $nCount) If @error Then Return SetError(1,0,False) Return True EndFunc Edited May 3, 2012 by Zedna JScript, genius257 and DXRW4E 3 Resources UDF ResourcesEx UDF AutoIt Forum Search
Zedna Posted May 3, 2012 Author Posted May 3, 2012 Here is old Feature request for native AutoIt's function StringRepeat() where Jon wasn't against adding it. Resources UDF ResourcesEx UDF AutoIt Forum Search
UEZ Posted May 3, 2012 Posted May 3, 2012 Nice function! Something for the giant WinAPIEx library. Thanks for sharing. Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
guinness Posted May 3, 2012 Posted May 3, 2012 Nice. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
KaFu Posted May 3, 2012 Posted May 3, 2012 Nice trick, can be used to change part of the buffers too. $nCount = 100 $sChar = "a" $tBuffer = DllStructCreate("char[" & $nCount & "]") DllCall("msvcrt.dll", "ptr:cdecl", "memset", "ptr", DllStructGetPtr($tBuffer), "int", Asc($sChar), "int", $nCount) ConsoleWrite(DllStructGetData($tBuffer, 1) & @CRLF) DllCall("msvcrt.dll", "ptr:cdecl", "memset", "ptr", DllStructGetPtr($tBuffer) + 5, "int", Asc("b"), "int", 10) ConsoleWrite(DllStructGetData($tBuffer, 1) & @CRLF) DllCall("msvcrt.dll", "ptr:cdecl", "memset", "ptr", DllStructGetPtr($tBuffer) + 5, "int", Asc(" "), "int", 10) ConsoleWrite(DllStructGetData($tBuffer, 1) & @CRLF) DllCall("msvcrt.dll", "ptr:cdecl", "memset", "ptr", DllStructGetPtr($tBuffer) + 50, "int", Asc(" "), "int", DllStructGetSize($tBuffer) - 50) ConsoleWrite(DllStructGetData($tBuffer, 1) & @CRLF) DllCall("msvcrt.dll", "ptr:cdecl", "memset", "ptr", DllStructGetPtr($tBuffer) + 75, "int", Asc("z"), "int", DllStructGetSize($tBuffer) - 75) ConsoleWrite(DllStructGetData($tBuffer, 1) & @CRLF) JScript 1 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2025-May-18) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
stormbreaker Posted May 3, 2012 Posted May 3, 2012 Good function. ---------------------------------------- :bye: Hey there, was I helpful? ---------------------------------------- My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1
JScript Posted May 3, 2012 Posted May 3, 2012 Excelente, thanks!!! Regards, João Carlos. http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere!
guinness Posted September 5, 2012 Posted September 5, 2012 Here is old Feature request for native AutoIt's function StringRepeat()where Jon wasn't against adding it.Due to the limitation this won't be replacing the currently implemented _StringRepeat. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
jvanegmond Posted September 5, 2012 Posted September 5, 2012 (edited) Due to the limitation this won't be replacing the currently implemented _StringRepeat. You can always do something like $s = StringRepeat("abc", 10) ConsoleWrite($s & @CRLF) Exit Func StringRepeat($sChar, $nCount, $msvcrt = "msvcrt.dll") $nLen = StringLen($sChar) $tBuffer = DLLStructCreate("char[" & ($nLen * $nCount) & "]") $aSplit = StringSplit($sChar, "") $pBase = DLLStructGetPtr($tBuffer) For $n = 1 to UBound($aSplit)-1 DllCall($msvcrt, "ptr:cdecl", "memset", "ptr", $pBase + ($n - 1), "int", Asc($aSplit[$n]), "int", 1) Next For $n = 0 To $nCount - 1 DllCall($msvcrt, "ptr:cdecl", "memcpy", "ptr", $pBase + ($n * $nLen), "ptr", $pBase, "int", $nLen) Next Return DLLStructGetData($tBuffer, 1) EndFunc but I have no clue if that's OK due to my limited C++ knowledge. I didn't speed test because I think it will be much slower. Edited September 5, 2012 by Manadar github.com/jvanegmond
Malkey Posted September 5, 2012 Posted September 5, 2012 Here is another StringRepeat example. $s = _StringRepeatRE("abc", 10) ConsoleWrite($s & @CRLF) ; [url="http://www.autoitscript.com/forum/index.php?showtopic=101594&view=findpost&p=722113"]http://www.autoitscript.com/forum/index.php?showtopic=101594&view=findpost&p=722113[/url] Func _StringRepeatRE($sString, $iRepeatCount) Return StringRegExpReplace(StringFormat("%" & $iRepeatCount & "s", " "), ".", $sString) EndFunc ;==>_StringRepeatRE
guinness Posted September 5, 2012 Posted September 5, 2012 but I have no clue if that's OK due to my limited C++ knowledge. I didn't speed test because I think it will be much slower.I highly doubt this. I will have a look at your changes and see if it's worth replacing with the current UDF. I will however be changing the function as it currently uses a Select...EndSelect for some reason.Here is another StringRepeat example.Thanks. Though StringFormat increases the execution time unfortunately. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
Spiff59 Posted September 6, 2012 Posted September 6, 2012 Neither the production version nor this DLL version seem very fast. This one-liner screams along for any size string but due to numeric limitations only works for 15 or less repeats ($nCount): Return StringReplace(10 ^ $nCount - 1, "9", $sChar) This is also just as fast but only handles as high an $nCount value as characters in the local constant: Local $str = "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" Return StringReplace(StringLeft($str, $nCount), "@", $sChar) IMHO, I don't see a need for a rarely-used UDF function that only replaces the following: For $x = 1 To $iRepeatCount $sResult &= $sString Next
Moderators SmOke_N Posted November 25, 2012 Moderators Posted November 25, 2012 (edited) I was searching Google for something and it led me to this link. After looking at it, and looking at guinness's concerns, I'd like to chime in. 1. IMO, there's no error for a function like this. The person(s) using the function are responsible for managing their parameters. 2. Anything using DllStruct-Create/GetData whatever, is going to be slower normally than a simple concatenation. The only time I could see this being different maybe, is if the strings are huge and memory starts to get eaten up, but AutoIt's memory management is pretty well setup, so I don't see that really happening. This is true for single Chars or 2+Chars. 3. StringFormat(); well, it's not meant for speed, that's for sure. Long story short, the only way I can see it being faster: 1. For long strings, dllcall to dll that manages the data itself without having to manage struct usage inside AutoIt. 2. Get rid of error checking. 3. We can save 1 loop cycle doing it the below way. Func _StringRepeat($sString, $nCount) If $sString = Chr(0) Then Return Local $sRStr = $sString For $i = 1 To Int($nCount) - 1 $sRStr &= $sString Next Return $sRStr EndFunc Edit: This may be faster even: Func _StringRepeat($sString, $nCount) Local $iLen = StringLen($sString) If $iLen = 0 Then Return Local $iMax = $iLen * $nCount While StringLen($sString) < $iMax $sString &= $sString WEnd Return StringLeft($sString, $iMax) EndFunc Edit2: The last one has my vote. After benchmarking each, it was the most consistent in time to finish ( loops tested from 1 to 500 repeats over and over ). At a certain point, it was never more than 3 or 4 milliseconds, while the others were 10, 20, 30+ milliseconds as the string grew (makes sense). Edited November 25, 2012 by SmOke_N JScript and Wiliat87 2 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
JScript Posted November 25, 2012 Posted November 25, 2012 @SmOke_NI fully agree with you!JS http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere!
guinness Posted November 25, 2012 Posted November 25, 2012 I would say (in the benchmarks I did) that this is quicker >> #2172 ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringRepeat ; Description ...: Repeats a string a specified number of times. ; Syntax ........: _StringRepeat($sString, $iRepeatCount) ; Parameters ....: $sString - String to repeat ; $iRepeatCount - Number of times to repeat the string ; Return values .: Success - Returns string with specified number of repeats ; Failure - Returns an empty string and sets @error = 1 ; |@error - 0 = No error. ; |@error - 1 = One of the parameters is invalid ; Author ........: Jeremy Landes <jlandes at landeserve dot com> ; Modified.......: guinness - Removed Select...EndSelect statement and replaced with an If...EndIf as well as optimised the code. ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _StringRepeat($sString, $iRepeatCount) If (Not StringIsInt($iRepeatCount)) Or StringLen($sString) < 1 Or $iRepeatCount <= 0 Then Return SetError(1, 0, "") Local $sResult = "" While $iRepeatCount > 1 If BitAND($iRepeatCount, 1) Then $sResult &= $sString $sString &= $sString $iRepeatCount = BitShift($iRepeatCount, 1) WEnd $sString &= $sResult Return $sString EndFunc ;==>__StringRepeat UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
Moderators SmOke_N Posted November 25, 2012 Moderators Posted November 25, 2012 (edited) I would say (in the benchmarks I did) that this is quicker >> #2172 I don't know how you benchmarked that, but that statement is not true. Edit: I just realized this was not a thread on this subject exactly, that it was a thread on using memset specifically for this, I will not hijack any further. My apologies Zedna. Edit2: ( Editing so not to bump ) Here's a fair benchmark test: expandcollapse popupGlobal $gstr_in = "aBcDeF" Global $gstr1, $gstr2 Global $gntimer1, $gntimer2 Global $gndiff1, $gndiff2 Global $gna1 = 0, $gna2 = 0 For $j = 1 To 10 For $i = 1 To 500 Switch Random(0, 9, 1) Case 0 To 4 Sleep(10) $gntimer1 = TimerInit() $gstr1 = _guinness($gstr_in, $i) $gndiff1 = TimerDiff($gntimer1) Sleep(10) $gntimer2 = TimerInit() $gstr2 = _SmOke_N($gstr_in, $i) $gndiff2 = TimerDiff($gntimer2) Case Else Sleep(10) $gntimer2 = TimerInit() $gstr2 = _SmOke_N($gstr_in, $i) $gndiff2 = TimerDiff($gntimer2) Sleep(10) $gntimer1 = TimerInit() $gstr1 = _guinness($gstr_in, $i) $gndiff1 = TimerDiff($gntimer1) EndSwitch $gna1 += $gndiff1 $gna2 += $gndiff2 Next Next ConsoleWrite("Guinness:" & @TAB & $gna1 & @CRLF & "SmOke_N:" & @TAB & $gna2 & @CRLF) Func _guinness($sString, $iRepeatCount) If (Not StringIsInt($iRepeatCount)) Or StringLen($sString) < 1 Or $iRepeatCount <= 0 Then Return SetError(1, 0, "") Local $sResult = "" While $iRepeatCount > 1 If BitAND($iRepeatCount, 1) Then $sResult &= $sString $sString &= $sString $iRepeatCount = BitShift($iRepeatCount, 1) WEnd $sString &= $sResult Return $sString EndFunc Func _SmOke_N($sString, $iCount) Local $iLen = StringLen($sString) If $iLen = 0 Then Return Local $iMax = $iLen * Int($iCount) While StringLen($sString) < $iMax $sString &= $sString WEnd Return StringLeft($sString, $iMax) EndFunc Edited November 25, 2012 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
JScript Posted November 25, 2012 Posted November 25, 2012 (edited) @guinness In this case Select / EndSelect is slower than If / EndIf? Inline is not slower, If BitAND($iRepeatCount, 1) Then $sResult &= $sString than this way:? If BitAND($iRepeatCount, 1) Then $sResult &= $sString EndIf JS Edited November 25, 2012 by JScript http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere!
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