Modify

Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

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

StringRepeat_Test.rar (1.5 KB ) - added by amarcruz 14 years ago.
Performance & functional test for new version of _StringRepeat

Download all attachments as: .zip

Change History (7)

by amarcruz, 14 years ago

Attachment: StringRepeat_Test.rar added

Performance & functional test for new version of _StringRepeat

comment:1 by amarcruz, 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:2 by TicketCleanup, 14 years ago

Version: 3.3.8.1

Automatic ticket cleanup.

comment:3 by guinness, 14 years ago

Resolution: Rejected
Status: newclosed

I didn't get the same results so at present I see no real need to update this function.

comment:4 by guinness, 14 years ago

Resolution: Rejected
Status: closedreopened

comment:5 by guinness, 14 years ago

Resolution: Completed
Status: reopenedclosed

comment:6 by guinness, 14 years ago

Added by revision [7255] in version: 3.3.9.5

Modify Ticket

Action
as closed The ticket will remain with no owner.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.