Here are the test results. All times are in milliseconds.
Number of Concatenations | String Length | VBScript Speed (ms.) | StrCat.Cutter Speed (ms) |
1 | 11 | .02 | .06 |
5 | 11 | .02 | .06 |
10 | 11 | .02 | .07 |
25 | 11 | 4.47 | .15 |
50 | 11 | .06 | .21 |
100 | 11 | .16 | .35 |
200 | 11 | 10.32 | .64 |
500 | 11 | 182.2 | 1.52 |
1000 | 11 | 144.01 | 2.98 |
2000 | 11 | 59.92 | 7.07 |
1 | 44 | .01 | .05 |
5 | 44 | .02 | .06 |
10 | 44 | .02 | .08 |
25 | 44 | .05 | .31 |
50 | 44 | .14 | .25 |
100 | 44 | 1.07 | .44 |
200 | 44 | 1.86 | .81 |
500 | 44 | 12.19 | 2.3 |
1000 | 44 | 140.20 | 5.51 |
2000 | 44 | 940.53 | 12.41 |
1 | 176 | .02 | .06 |
5 | 176 | .03 | .09 |
10 | 176 | .04 | .14 |
25 | 176 | .67 | .33 |
50 | 176 | 1.01 | .55 |
100 | 176 | 7.4 | 1.04 |
200 | 176 | 10.09 | 2.45 |
500 | 176 | 215.33 | 7.86 |
1000 | 176 | 1825.91 | 18.68 |
2000 | 176 | 9137.12 | 38.78 |
1 | 484 | .02 | .08 |
5 | 484 | .05 | .16 |
10 | 484 | .10 | .43 |
25 | 484 | 3.66 | .73 |
50 | 484 | 1.59 | 1.44 |
100 | 484 | 5.65 | 3.80 |
200 | 484 | 150.13 | 11.31 |
500 | 484 | 1467.19 | 25.16 |
1000 | 484 | 6414.08 | 58.50 |
2000 | 484 | 26419.2 | 112.03 |
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 concatenations, Catter lags behind. But once VB starts to slow down, it does so disastrously – quadratically, in fact – while 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.
Conclusion
When you need to concatenate more than a few dozen strings, consider using StrCat.Catter. Catter’s optimized C++ implementation can prevent your site from CPU saturation when folks start asking more of it than VB can handle.
Shameless Plug
These and many other cutting-edge techniques power www.streamload.com, a web storage and delivery site offering unlimited free online storage for your files. Upload all your files from your computer to gain format-savvy access to them from anywhere.
Features include image slideshows, audio and video streaming and playlists, and streamlined download management. Also, share and sell your own digital creations. This is not another drive site: This is your digital entertainment, online.
Michael Balloni
Streamload Development
http://www.streamload.com
Article published with the express written permission of the author.
Copyright 2000 Michael Balloni
]]>