Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Aug 7, 1998

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 MyClass
Dim generic As Object
Dim start_time As Single
Dim stop_time As Single
Dim 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
Rod Stephens
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date