Integer Speed projects |
These projects show the speed
differences between the data types Variant, Integer, and Long. There is a relatively large
difference in the speed of Variants when running interpreted p-code inside the Visual
Basic IDE. But there is a HUGE difference when running variants using compiled native code
as a stand-alone EXE file.
Here are the timing results for the Version 4 compiled program. I clicked
on the "Run All 3" button three times, and waited for all the loops to finish
executing before clicking again. I discarded the first of the three sets of results,
because they were usually slower than the subsequent results. I then averaged the other
two sets of results to produce the values shown below. |
Windows 98
Visual Basic 5.0 |
300 Mhz Pentium II, using Int
Speed 4 VB5.exe |
Long |
0.12 seconds |
Integer |
0.26 seconds, 2.1 times slower than Long |
Variant |
3.08 seconds, 24.8 times slower than Long |
Windows 98
Visual Basic 6.0 |
300 Mhz Pentium II, using Int
Speed 4 VB6.exe |
Long |
0.13 seconds |
Integer |
0.26 seconds, 2.1 times slower than Long |
Variant |
3.36 seconds, 26.8 times slower than Long |
Windows NT 4 |
When I ran these projects under Windows NT Server
4.0, they acted differently. When I clicked the button for "Run All 3", the
screen did not repaint until after ALL three loops had finished. This certainly looked a
bit strange, but the timing results for the compiled program were similar to those shown
above. |
Windows NT 4
Visual Basic 6.0 |
450 Mhz Pentium II, using Int
Speed 4 VB6.exe |
Long |
0.08 seconds |
Integer |
0.17 seconds, 2.1 times slower than Long |
Variant |
2.21 seconds, 27.6 times slower than Long |
Conclusions |
There are certain rare cases in
which you MUST use variant data types. Clearly, you should avoid them because your
programs will run slower if you use them.
Note that Longs are faster than Integers. Because the code is running
under a 32 bit operating system, the code is more efficient at manipulating Longs, which
occupy 32 bits (4 bytes of 8 bits each). Under 16 bit Windows, the results would be
faster for Integers, since they occupy 16 bits (2 bytes of 8 bits each). |