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
See also  5 Tips for Working With an Onsite Interpreter
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist