» Home » VB Fibre
Site
News
Files

Visual Basic
Strings
Math
General
Properties
Memory
Methods

Search
Testing

Inline ASM-VB
Strings
Math
General
Memory

Search
Using inline ASM
Submit!

Early vs. Late binding

Well, the difference is really unproportional =-) Just to make something clear:

Early binding: Checking the object under "references" and use "Dim X as ObjectName"
Late binding: Using "Dim X as Object" and later "Set X = CreateObject("ObjectName")

I made a small ActiveX dll with the following code:

Code:
Public Function PerformCalculation(lngValue1 As Long, lngValue2 As Long) As Long PerformCalculation = lngValue1 lngValue2 End Function
Then I referenced one variable using "References". Then I set the variables correctly in the Declaration section:
Declarations:
Private objTest1 As Object Private objTest2 As VbFibreTest.clsCalc
Their instance was created using:
Code:
'//Create objects Set objTest1 = CreateObject("VbFibreTest.clsCalc") Set objTest2 = New clsCalc
And finally this was called 5x500.000 times:
Code:
Public Sub TestOne() Dim lngReturn As Long lngReturn = objTest1.PerformCalculation(100, 50) End Sub Public Sub TestTwo() Dim lngReturn As Long lngReturn = objTest2.PerformCalculation(100, 50) End Sub

Late % faster than Early Late (sec) Early (sec)
3772,6% 6,404157 0,165373
3818,2% 6,454636 0,164735
3792,6% 6,378763 0,163867
3498,2% 6,396008 0,177755
3573,8% 6,406381 0,174380


User contributed notes:

Author: VBBR () Date: 23:03 20/03/2004
And are there any speed differences between

Dim a as SomeThing
'later on...
Set a = New SomeThing

and

Dim a as New SomeThing

???

Author: VBBR () Date: 22:03 31/03/2004
Oh, I just saw a separate test for that, sorry.

Author: Tom (hurendo_kun at hotmail dot com) Date: 04:09 23/09/2005
Late-binding also occurs when you declare "Dim obj as Object" and set it later with "Set obj = New objType." Using the CreateObject function will make it considerably slower because not only is it a function call, but it has to look up the object definition in the type library. Maybe you should add a third test to the mix?

Add user-note
Author:
E-mail (optional):
Anti spam, please enter 'ok' without quotes:
Comment: