Remember to show that there are *two* major chokepoints in string operations.
One goin' in, one comin out. It doesn't just choke, it gets asthma.
Overview of String Articles
Introduction
- String processing is notoriously slow in both VB and
VBScript.
- This series of articles discusses why string operations
are so slow and outlines a number of ways to speed it up.
- If you just want faster string processing without worrying
about *how* the faster implementations actually work, read
[todo: link] article#4.
- If you want to understand why strings are so slow in VB
and VB Script, read
Article#1: Why String Operations are so Slow.
- If you want to see how the classes and extra functions
work, and why they improve performance, read
article#2
- Faster Strings in VBScript
(for pure VBScript) and/or
article#3 - Faster Strings in Pure VB
(for VB COM Component
solutions).
- It may surprise you to discover that, in most cases,
using API calls is NOT the best way to speed up string operations
in VB. VB is bad at API calls, and the overhead of
making the calls will often more than offset the
speed improvement to be gained in them. [Todo:
See article#3, which provides examples illustrating this.]
- The early articles in this series cover ways to speed up
operations without changing the way that strings are represented.
Later articles discuss ways to change the representation to
make additional (but smaller) gains, at the expense of
program complexity
- I intend to include an article with source code and
a compiled version of a C++ DLL, which will give another
increase in performance, for some operations
Articles
- Why String
Operations are so Slow
The first article discusss why string operations are slow in
both VBScript and VB, and provides performance graphs showing that,
for many operations, the execution time increases with the
square of the length of the target string, when it
should be increasing at the same rate as the length of
the target string.
-
Faster string functions in VBScript
This article provides source code for (and discussion of)
several routines which will improve string performance in
VBScript. Note that, in some cases, the performance improvements
are only modest (as VBScript doesn't have a Mid statement,
only a Mid function).
- Faster string functions in VB
This article provides source code for (and discussion of)
several routines which will greatly improve string performance in
VB. While some of these routines perform worse than the built-in
ones (for small strings), they all perform MUCH better for
long strings, or very repetitive sequences of operations.
Many have linear performance. So instead of taking
100 times longer to process 10 times the data, they take 10 times
longer. Some (like the string concatenation routines) do not
do so well. These have N*log(N) performance, and will
take about 33 times longer to process 10 times the data.
Code Examples:
- InstrNext() - a function which finds the next occurrence
of a substring in a string (when given the index of the previous
one).
- InstrAfter() - a function which find the *end* of the
next occurrence of a substring in a string.
- LinearJoin() - a version of Join() which scales better
for very large arrays.
- LinearSplit() - a version of Split() which scales better
for very large arrays, and performs much better for
case-insensitive splits.
- LinearReplace() - a version of Replace() which performs
much better for case insensitive string-replacement, and
scales better for ordinary string-replpacement
- LinearFind() - a routine which finds occurrences of a
substring in another string, *without* creating new strings
or making copies of the old
- clsConcatenatedString() - a class that helps you
concatenate strings faster (it gives N*Log(N) performance).
- clsLinearString() - a class that concatenates strings
even faster (and gives linear performance even for VERY
long strings).This one will scale up to about 110Mb. The
other class only scales to about 2Mb.
- Identifying string performance bottlenecks
- Avoiding string operations altogether