The release of VB5 at last gave VB programmers a chance to compile their VB applications to Native code. When you compile your VB project, and decide whether to compile as Native or P-code, and Fast or Small, there are a number of things to consider. To change any of these settings of your program, click the Compile tab on the project properties dialog.
The first is speed. How important this is depends on the type of program you are writing. Below is some results on a PIII 500Mhz, using the code below as the 'stuff to do'.
For I = 0 To 1000000 Step 0.1
A = Sqr(I) + A
z = A / 32.34
Next
Compile Mode | Time Taken |
Native Code - Fast Code | 8.077 |
Native Code - Small Code | 9.1745 |
Native Code - Fast Code (Favour Pentium) | 8.7876 |
Native Code - Small Code (Favour Pentium) | 8.9505 |
Native Code - No Optimization | 9.4461 |
P-Code | 9.5598 |
Run-time | 10.0695 |
As you can see, P-code is significantly slower than when compiling to Native Code.
The other is size. When you are distributing your program using CD-rom, this is not very significant. However, if you are making your program available over the internet, things are different. Below is the different sizes of my Developers Pad program when compiled in the different modes.
Compile Mode | Size |
Native Code - Fast Code | 816KB |
Native Code - Small Code | 772KB |
Native Code - No Optimization | 876KB |
P-Code | 472KB |
As you can see, P-code is also significantly smaller than when compiling to Native Code. What you will have to decide on, is which mode you want to use. This will all depend on how you are distributing your program, and how important speed actually is. For simple things such as a Word processor, speed would not be very important (unless you perform a large amount of processing as the user is typing), and you may opt for the smaller executable file.
It is also worth noting that compiling to P-code is much, much quicker than compiling to Native code.
*** If you want to detect as many possible errors without compiling, start your program by pressing Ctrl+F5 instead of F5, as this will compile your program fully. You can also do this by unchecking compile on demand in the options dialog. Thanks to Magik for pointing this out to me. You can visit his website @ magikweb.cjb.net ***
Comments