Updated the module:
- .Add method can now take any number of parameters
Few tips on when to use this:
Uses "StringBuilder", "Console"
Function TBMain()
Dim stringBuffer As String
Dim sb As StringBuilder
sb = New StringBuilder()
Long i
Dim stopWatch As cTimer
stopWatch = New cTimer()
PrintL "Appending to classic string: "
stopWatch.Start
For i = 1 To 20000
stringBuffer += "Appending is fine! (" + i + ")"
Next
stopWatch.Stop
PrintL stopWatch.ElapsedToString(%CTIMER_MILLISECONDS, "0") + " ms (Total " + Len(stringBuffer) + " characters)"
PrintL
PrintL "Appending to classic string with StrFormat$: "
stringBuffer = ""
stopWatch.Start
For i = 1 To 20000
stringBuffer += StrFormat$("Appending is fine! ({1})", i)
Next
stopWatch.Stop
PrintL stopWatch.ElapsedToString(%CTIMER_MILLISECONDS, "0") + " ms (Total " + Len(stringBuffer) + " characters)"
PrintL
PrintL "Appending to string builder with StrFormat$: "
stopWatch.Start
For i = 1 To 20000
sb.Add(StrFormat$("Appending is fine! ({1})", i))
Next
stopWatch.Stop
PrintL stopWatch.ElapsedToString(%CTIMER_MILLISECONDS, "0") + " ms (Total " + Len(sb.ToString()) + " characters)"
PrintL
PrintL "Appending to string builder with multiple parameters: "
sb.Clear()
stopWatch.Start
For i = 1 To 20000
sb.Add("Appending is fine! (", i, ")")
Next
stopWatch.Stop
PrintL stopWatch.ElapsedToString(%CTIMER_MILLISECONDS, "0") + " ms (Total " + Len(sb.ToString()) + " characters)"
PrintL
printl "Press any key to quit..."
WaitKey
End Function
Petr
Bookmarks