» 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!

"Dim X as New Y" vs. "Set X = New Y"

Slightly speed increase here, The "Set X = New Y" variant is a bit faster than the "Dim X as New Y" direct method. I used the DLL that I made for Early vs. Late binding.

Declarations:
Dim ObjTest1 As New VbFibreTest.clsCalc Dim ObjTest2 As VbFibreTest.clsCalc

Start:
'//Set second object Set ObjTest2 = New VbFibreTest.clsCalc

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

New Direct % faster than New Indirect New Direct (sec) New Indirect (sec)
11,8% 0,187517 0,167713
24,5% 0,209374 0,168185
3% 0,186233 0,180870
9,5% 0,185430 0,169378
11,9% 0,189575 0,169456


User contributed notes:

Author: Tom (hurendo_kun at hotmail dot com) Date: 15:06 08/06/2005
When using "As New", the compiler adds a conditional "If obj Is Nothing Then Set obj = New class" before every property and procedure call, yielding a slight performance hit. In most cases, this is negligible, but if you're working with high-performance algorithms, you should declare "As class" and create the object manually.

Author: Almar () Date: 19:06 08/06/2005
Thanks for sharing your useful knowledge Tom, I really appreciate it (I'm sure there are others too ;))

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