Jump to content
Sign in to follow this  
Zedna

StringRepeat - very fast (using memset)

Recommended Posts

Zedna

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)
EndFunc

Testing 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)
EndFunc

EDIT:

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 by Zedna
  • Like 3

Share this post


Link to post
Share on other sites
UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
guinness

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
KaFu

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)
  • Like 1

Share this post


Link to post
Share on other sites
stormbreaker

Good function. ;)


----------------------------------------

:bye: Hey there, was I helpful?

----------------------------------------

My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1

Share this post


Link to post
Share on other sites
guinness

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
jvanegmond

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

Share this post


Link to post
Share on other sites
Malkey

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

Share this post


Link to post
Share on other sites
guinness

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
Spiff59

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

Share this post


Link to post
Share on other sites
SmOke_N

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 by SmOke_N
  • Like 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.

Share this post


Link to post
Share on other sites
guinness

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
SmOke_N

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:

Global $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 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.

Share this post


Link to post
Share on other sites
JScript

@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 by JScript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

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  

  • Similar Content

    • nooneclose
      By nooneclose
      I need help turning this string "20180913221626" into a formatted time string.
      I need to go from this: 20180913221626
      to this: 09/13/2018 10:16 PM
      I do not always know what the date will be so I can not just use a variable I need to actually convert/format. 
      I did see an older post in the forms that was basically the same question only the other guy did not post the working code and I can not figure out how to use _AD_GetObjectProperties properly to get what I want. 
      As always any help would be appreciated. 
      Here is the code I use to find the date, but it always gives me the unformatted version. 
      ;retrieve the items object $oItem = $oOutlook.Session.GetItemFromID($aItems[1][0], Default) $oItem.GetInspector $eSentOn = $oItem.SentOn ; When was the email sent? MsgBox("", "Sent On of the email", $eSentOn) ;******************************************************************************* ; Formats the date and time from the email ;******************************************************************************* ;Local $fDatenTime = _DateTimeFormat($eSentOn, 1) ;MsgBox("", "Formatted email time", $fDatenTime) $aProperties = _AD_GetObjectProperties($eSentOn) _ArrayDisplay($aProperties, "Did the conversion work?")  
    • mrtgtr
      By mrtgtr
      I want to do something , after wait 2 min and again do same thing
      But I do do not want with sleep, it must be timer 
      How I do this ?
    • Miliardsto
      By Miliardsto
      I got that func
      Func makeHelpImgGUI($title,$width,$height,$img) $img = GUICtrlCreatePic("",20,40,$width,$height) _ResourceSetImageToCtrl($img, "HERE") EndFunc and I call this func like that
      makeHelpImgGUI("Image",1190, 800,$SETTINGS_JPG)  
      so what is the problem in the parameter where is - "HERE" I need value of img but passed as string
      so $img = $SETTINGS_JPG and how make it "SETTINGS_JPG"
       
      I tried something like that but not work
      Func makeHelpImgGUI($title,$width,$height,$img) $name_str = String($img) $name_str = StringTrimLeft ($name_str, 1 ) $img = GUICtrlCreatePic("",20,40,$width,$height) _ResourceSetImageToCtrl($img, $name_str) EndFunc  
    • liagason
      By liagason
      Hello everyone,
      How can I display in ascending  sequence some numbers stored in a string variable?
      $str = "18,03,48,23" MsgBox(0,"test",$str) I would like it to display "03,18,23,48"
    • Rskm
      By Rskm
      Hi, I have the following line in a text file 'input.txt'. I know the line number - say '6'. I wish to replace the text 'WWW' in the below line with a random number (I can generate that with random()).
      WERIS  WWWJP   3.83  8.330  1.000                1097.RAXX 
      The WWW is a 3 digit integer (could be any number between 0 to 999), I can use stringtrimleft and get the numerical value of WWW in this file
      so, basically, I know the string to replace (ie; WWW stored in a variable), I know the line number to work on and the file location/name and the replacement variable (through random()). My requirement is to fill that 3 spaces with my random number (which Is a integer between 1 and 999)
      please put ur suggestions
       
×