Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 28,039 times

Contents

Related Categories

Performance Issues - Compiling

Compiling

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 ***

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • Once Again!

    Posted by MahR on 29 Sep 2005

    And once again a greate article by james!

  • Use of ByRef and ByVal

    Posted by JonathanEvans on 21 Mar 2002

    This posting is specifically a response to James Cowleys suggestion that using ByVal is quicker than using ByRef. This is only true when calling an out-of-process server (i.e. and ActiveX EXE). VB i...