String Concatenation Component

The results

Usage
I like to use this component for concatenation of SQL query strings, both in VB and in ASP scripts. SQL Server devours big batches of SQL much better than lots of little requests. Since Catter is so efficient, great gains can be had when the size of the strings and the number of concatenations grows. As an example, I use this component to manufacture SQL that marks all of a set of database-modelled files and folders and their children folders and files as public or private. If there are just a few files and folders, you can get away with VB string concatenation. Throw in a few thousand files and deeply nested folders, and you need the improved performance of Catter.

Performance
Catter outperforms standard VB string concatenation after several dozen concatenations. Here's The results can be seen below. If you're interested in the code tests I used, check out the VB test code used. Note that is employs the use of a free component, ASP Profiler. To run this code you will need to download and install the component.

Concatenations
Length of String
VBScript Concatenation
StrCat.Catter Concatenation
1 44 0.01 0.05
5 44 0.02 0.06
10 44 0.02 0.08
25 44 0.05 0.31
50 44 0.14 0.35
100 44 1.07 0.44
200 44 1.86 0.81
500 44 12.19 2.30
1000 44 140.20 5.51
2000 44 940.53 12.41
200 484 150.13 11.31
500 484 1,467.19 25.16
1000 484 6,414.08 58.50
2000 484 26,419.20 112.30

Times in milliseconds

You can see that it takes about three times longer to get Catter up to speed for a single concatenation, and even after a few dozen Catter lags behind. But once VB starts to slow down, it does so disastrously - quadratically, in fact - and Catter keeps its cool, staying almost linear in terms of time versus concatenations. I'd hate to be the person waiting 25 seconds for VB to concatenate some strings!

Implementation
Catter is an STL vector of STL wstrings. Catter's implementation calls on the reserve methods of both the vector and wstring classes. The implementations of these classes are designed so that their execution time stays linear under these circumstances. They accomplish this by doubling their allocated memory when they need to grow, thereby avoiding making too many allocations and fragmenting the heap.

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“God could create the world in six days because he didn't have to make it compatible with the previous version.”