Modify ↓
#2172 closed Feature Request (Completed)
_StringRepeat addition, increments performance with higher count
| Reported by: | amarcruz | Owned by: | |
|---|---|---|---|
| Milestone: | Component: | Standard UDFs | |
| Version: | Severity: | None | |
| Keywords: | udf, _stringrepeat, performance, modifications | Cc: |
Description
Hi,
_StringRepeat is efficient, but its performance degrades with high values in its $iRepeatCount parameter.
To correct this, I'm proposing an amendment to _StringRepeat(), like this:
Func _StringRepeat($sString, $iRepeatCount) ;============================================== ; Local Constant/Variable Declaration Section ;============================================== Local $sResult Select Case Not StringIsInt($iRepeatCount) SetError(1) Return "" Case StringLen($sString) < 1 SetError(1) Return "" Case $iRepeatCount <= 0 SetError(1) Return "" Case $iRepeatCount < 50 ;<=== changed, test for low count For $iCount = 1 To $iRepeatCount $sResult &= $sString Next Return $sResult EndSelect ;=== added block, for $iRepeatCount >= 50, minimizes the steps While $iRepeatCount > 1 If BitAND($iRepeatCount, 1) Then $sResult &= $sString $sString &= $sString $iRepeatCount = BitShift($iRepeatCount, 1) WEnd $sString &= $sResult Return $sString ;=== end of added block EndFunc ;==>_StringRepeat
For example (In my PC):
_StringRepeat("X", 4000) takes 6461.5 ms, new version 228.6
Attached is functional and performance tests.
Attachments (1)
Change History (7)
by , 14 years ago
| Attachment: | StringRepeat_Test.rar added |
|---|
comment:1 by , 14 years ago
I forgot, that's useful when you want to fill a large buffer for write to a file (2k+ ID3 tag padding, filled with 0's).
comment:3 by , 14 years ago
| Resolution: | → Rejected |
|---|---|
| Status: | new → closed |
I didn't get the same results so at present I see no real need to update this function.
comment:4 by , 14 years ago
| Resolution: | Rejected |
|---|---|
| Status: | closed → reopened |
comment:5 by , 14 years ago
| Resolution: | → Completed |
|---|---|
| Status: | reopened → closed |
Note:
See TracTickets
for help on using tickets.

Performance & functional test for new version of _StringRepeat