StrCat.Catter – An Efficient String Concatenation Component

Performance
Catter outperforms standard VB string concatenation after several dozen concatenations. Here’s the VB test code I used to test Catter’s performance as compared to VBscript. The results of the test are also below.

<%

‘ Test out CAT’ing.

Private Sub TestCat()
Dim test_str As String
test_str = “foo foo bar”
TestCatFor 1, test_str
TestCatFor 5, test_str
TestCatFor 10, test_str
TestCatFor 25, test_str
TestCatFor 50, test_str
TestCatFor 100, test_str
TestCatFor 200, test_str
TestCatFor 500, test_str
TestCatFor 1000, test_str
TestCatFor 2000, test_str
‘TestCatFor 5000, test_str
‘TestCatFor 10000, test_str

test_str = “asd;fjas;dlfu =8-081254j kuva nfajoiruawior “
TestCatFor 1, test_str
TestCatFor 5, test_str
TestCatFor 10, test_str
TestCatFor 25, test_str
TestCatFor 50, test_str
TestCatFor 100, test_str
TestCatFor 200, test_str
TestCatFor 500, test_str
TestCatFor 1000, test_str
TestCatFor 2000, test_str
‘TestCatFor 5000, test_str
‘TestCatFor 10000, test_str

test_str = “asd;fjas;dlfu =8-081254j kuva nfajoiruawior asd;fjas;dlfu =8-081254j kuva nfajoiruawior asd;fjas;dlfu =8-081254j kuva nfajoiruawior asd;fjas;dlfu =8-081254j kuva nfajoiruawior “
TestCatFor 1, test_str
TestCatFor 5, test_str
TestCatFor 10, test_str
TestCatFor 25, test_str
TestCatFor 50, test_str
TestCatFor 100, test_str
TestCatFor 200, test_str
TestCatFor 500, test_str
TestCatFor 1000, test_str
TestCatFor 2000, test_str
‘TestCatFor 5000, test_str
‘TestCatFor 10000, test_str

test_str = “asd;fjas;dlfu =8-081254j kuva nfajoiruawior asd;fjas;dlfu =8-081254j kuva nfajoiruawior asd;fjas;dlfu =8-081254j kuva nfajoiruawior asd;fjas;dlfu =8-081254j kuva nfajoiruawior asd;fjas;dlfu =8-081254j kuva nfajoiruawior asd;fjas;dlfu =8-081254j kuva nfajoiruawior asd;fjas;dlfu =8-081254j kuva nfajoiruawior asd;fjas;dlfu =8-081254j kuva nfajoiruawior asd;fjas;dlfu =8-081254j kuva nfajoiruawior asd;fjas;dlfu =8-081254j kuva nfajoiruawior asd;fjas;dlfu =8-081254j kuva nfajoiruawior “
TestCatFor 1, test_str
TestCatFor 5, test_str
TestCatFor 10, test_str
TestCatFor 25, test_str
TestCatFor 50, test_str
TestCatFor 100, test_str
TestCatFor 200, test_str
TestCatFor 500, test_str
TestCatFor 1000, test_str
TestCatFor 2000, test_str
‘TestCatFor 5000, test_str
‘TestCatFor 10000, test_str
End Sub

Private Sub TestCatFor(B
yVal iters As Long, ByVal testStr As String)
Dim prof As Object
Set prof = CreateObject(“Softwing.Profiler”)

Dim i As Long
Dim max_i As Long

max_i = iters

‘ Go traditional.
prof.ProfileStart
Dim str As String
For i = 0 To max_i
str = str & testStr
Next

Dim slow_ms As Double
slow_ms = prof.ProfileStop

‘ Go cat.
prof.ProfileStart
Dim strcat As Catter
Set strcat = New Catter
For i = 0 To max_i
strcat testStr
Next

Dim cat_str
cat_str = strcat.Dump

‘ Clean up the catter.
Set strcat = Nothing

‘ Stop the clock.
Dim cat_slow_ms As Double
cat_slow_ms = prof.ProfileStop

‘ Check that CAT did the same as traditional.
Debug.Assert cat_str = str

‘ Clean up the profiler.
Set prof = Nothing

‘ Output results.
Debug.Print iters & ” Run (” & Len(testStr) & “): ” & FormatNumber(slow_ms / 10) & ” vs. ” & FormatNumber(cat_slow_ms / 10)
End Sub
%>

Continues…

Leave a comment

Your email address will not be published.