Problem | P-Code | Native Code |
Local Basic function | .1270 sec | .0380 sec |
Early-bound Local Basic class, one at a time | .1750 sec | .0400 sec |
Late-bound Local Basic class, one at a time | .7550 sec | .6120 sec |
Early-bound Local Basic class, all at once | .1460 sec | .0330 sec |
Late-bound Local Basic class, all at once | .1540 sec | .0330 sec |
Basic global function in DLL | .1210 sec | .0350 sec |
Early-bound Basic class in DLL, one at a time | .1710 sec | .0390 sec |
Late-bound Basic class in DLL, one at a time | .8380 sec | .6040 sec |
Early-bound Basic class in DLL, all at once | .1450 sec | .0330 sec |
Late-bound Basic class in DLL, all at once | .1510 sec | .0330 sec |
Early-bound Basic class in EXE, one at a time | 9.8660 sec | 9.2240 sec |
Late-bound Basic class in EXE, one at a time | 20.5320 sec | 18.9650 sec |
Early-bound Basic class in EXE, all at once | .2040 sec | .0810 sec |
Late-bound Basic class in EXE, all at once | .2210 sec | .1040 sec |
Basic class in control, one at a time | .5930 sec | .3660 sec |
Basic class in control, all at once | .1470 sec | .0340 sec |
Early-bound C++ class in ATL DLL, one at a time | NA | .0150 sec |
Late-bound C++ class in ATL DLL, one at a time | NA | .2900 sec |
Early-bound C++ class in ATL DLL, all at once | NA | .0150 sec |
Late-bound C++ class in ATL DLL, all at once | NA | .0160 sec |
Early-bound C++ class in MFC DLL, one at a time | NA | .0830 sec |
Late-bound C++ class in MFC DLL, one at a time | NA | .1660 sec |
Early-bound C++ class in MFC DLL, all at once | NA | .0230 sec |
Late-bound C++ class in MFC DLL, all at once | NA | .0240 sec |
‘ Set variable at run time
Dim sieveLate As Object
Select Case cboServer.ListIndex
Case estBasicLocalClass
Set sieveLate = New CSieve
#Const fUseTypeLib = 1
#If fUseTypeLib Then
Case estBasicDllPCode
Set sieveLate = New CSieveBasDllP
Case estBasicDllNative
Set sieveLate = New CSieveBasDllN
§
#Else
Case estBasicEXE
Set sieveLate = CreateObject(“SieveBasDllP.CSieveBasDllP”)
Case estBasicDllNative
Set sieveLate = CreateObject(“SieveBasDllN.CSieveBasDllN”)
§
#End If
End Select
sieveLate.MaxPrime = txtMaxPrime.Text
If chkAll = vbUnchecked Then
‘ Get one at a time
ms = timeGetTime()
For i = 1 To cIter
sieveLate.ReInitialize
Do
iPrime = sieveLate.NextPrime
‘ More of the same...
Notice that there are two ways of creating a new late-bound object—one using the New statement and the other using CreateObject. In this case, there’s a type library, so New is slightly more efficient. But in most cases where you have a type library, you can use early binding. Use CreateObject for those cases (rare in my experience) where you don’t have a type library or don’t know the name of the class until run time.
NOTE You shouldn’t think of your DLL or OCX components as complete until you select the DLL base address. You do this on the Compile tab of the Project Properties dialog box. Visual Basic gives you a default base address, but if you accept it, your component will have a very good chance of being bumped by one of the other dummies who accepted the default address instead of selecting their own. If two components in the system have the same base address, the operating system will have to relocate one or the other. You don’t want it to be yours. The operating system expects base addresses to be on 64-KB boundaries, so there are 32,512 64-KB chunks in the available address range. You have a very good chance of avoiding everybody else’s range if you select your range randomly. The Address-o-matic program (as seen on TV) doesn’t aspire to being a wizard, but it will assign you a base address that isn’t in my range or in the Visual Basic range. You could enhance it to keep a database of known addresses to avoid, including the ranges for your company, your clients, and major component vendors. By the way, my range is one megabyte starting at &H2E8B0000. Keep out!