devxlogo

Use Explicit Object Types for Speed

Use Explicit Object Types for Speed

It is much faster to use explicit object data types instead of generic ones. In this test that simply sets an object’s public variable, the generic object takes more than 150 times longer than the specific object:

 Private Sub Command1_Click()Dim specific As MyClassDim generic As ObjectDim start_time As SingleDim stop_time As SingleDim i As Long	Set specific = New MyClass	Set generic = New MyClass	start_time = Timer	For i = 1 To 100000		specific.value = i	Next i	stop_time = Timer	MsgBox Format$(stop_time - start_time)	start_time = Timer	For i = 1 To 100000		generic.value = i	Next i	stop_time = Timer	MsgBox Format$(stop_time - start_time)End Sub

devx-admin

Share the Post: