Benchmark: Excel Calling Visual Basic 4.0

As an example of the above discussions, the CD contains samples of two VBA objects (with source code). These objects are called from VBA in early-bound and late-bound fashion as well as in-process and cross-process. The objects accept three string parameters, concatenate them, and return the result. The VBA source code listing is shown at the end of this chapter.

To create a meaningful benchmark, the code loops a variable number of times. The following results were obtained from running the code for 10,000 iterations.

In-Process

Cross-Process

Early Bound

0 seconds

13 seconds

Late Bound

3 seconds

32 seconds


The actual times are not important, as these can vary from machine to machine, depending on its configuration. The ratio between the times is the important factor. As the table above shows, the most important consideration when looking at this performance data is whether the object runs in-process versus cross-process. This single change can yield a 10x to 13x performance increase. Performance due to early versus late binding is not affected nearly as much, on the order of 3x in this test.

All this must be kept in perspective. If your code isn't running a loop and makes a single call or two, the difference between the two methods is often insignificant.