How I Time
I will time your code, and I will decide who's the winner. Here is how I do it:
- Generally, performance timing under Windows is not a trivial thing when you want the real truth in exact CPU cycles or nano-seconds, because there's a lot of background noise in a multi-tasking environment. However, for our purpose, relative speed measurement is all we need, and that can be done well enough.
- I use the QueryPerformanceCounter API, and it ticks 1,193,180 times per second on my Pentium II and 3,579,545 times per second on my Athlon XP. You can download the (VB5-)class I wrote for this if you're interested: download CTiming.cls (zipped, 2KB, update 15-sep-2004). Check out more details on the History of Profiling Windows and on how far we can trust those 1,193,180 (3,579,545) ticks...
- The test environment:
- till July 2002: Pentium II 350, 64 RAM, Win95, IE5.0
- after July 2002: Athlon XP 2000+, 256 RAM, Win XP Pro SP1, IE6.0
- All timing is done with VB5 and VB6, compiled to native code, optimized for speed, not (since 16-Nov-2001) favoring PentiumPro, and having all Advanced Optimizations enabled, in other words having all checks turned off.
Note, that you have to test your applications carefully before you turn all checks off. I found, that especially "Remove Integer Overflow Checks" can lead to pretty nasty and hard to track errors.
- By the way, comparing VB5 and VB6, VB5 is most of the times a bit faster than VB6. But I wouldn't bet on this...
- I run the candidate code thru a loop of several 100,000 iterations (called as a Public procedure located in a BAS-module), and I do this several times. From the collected results I calculate an average value, so that the average multi-tasking noise is part of the final number.
- Note: still, the resulting numbers are highly specific to the setup of the operating system, and it's very probable that they would come out differently on your computer. For example, I observed, that after installing IE5, almost everything slowed down, some functions even by ca. 50%!
- There's a lot more to say about VB performance and timing, some of it pretty strange actually ... i'll come back to this when I get the time.