Modify

Opened 7 years ago

Closed 7 years ago

Last modified 7 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 7 years ago.
Performance & functional test for new version of _StringRepeat

Download all attachments as: .zip

Change History (7)

Changed 7 years ago by amarcruz

Performance & functional test for new version of _StringRepeat

comment:1 Changed 7 years ago by amarcruz

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 Changed 7 years ago by TicketCleanup

  • Version 3.3.8.1 deleted

Automatic ticket cleanup.

comment:3 Changed 7 years ago by guinness

  • Resolution set to Rejected
  • Status changed from new to closed

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

comment:4 Changed 7 years ago by guinness

  • Resolution Rejected deleted
  • Status changed from closed to reopened

comment:5 Changed 7 years ago by guinness

  • Resolution set to Completed
  • Status changed from reopened to closed

comment:6 Changed 7 years ago by guinness

Added by revision [7255] in version: 3.3.9.5

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.