Click here to Skip to main content
15,881,089 members
Articles / Programming Languages / MSIL

Dynamic Objects, Factories, and Runtime Machines to Boost Performance

Rate me:
Please Sign up or sign in to vote.
4.79/5 (10 votes)
27 Nov 2007CPOL7 min read 48.1K   303   46  
An examination of dynamic object instantiation and runtime machines to boost performance.
Public Class Counter
	Private elapsedCount As Long = 0
	Private startCount As Long = 0

	Public Sub Start()
		Clear()
		startCount = 0
		QueryPerformanceCounter(startCount)
	End Sub

	Public Sub [Stop]()
		Dim stopCount As Long = 0
		QueryPerformanceCounter(stopCount)

		elapsedCount += (stopCount - startCount)
	End Sub

	Public Sub Clear()
		elapsedCount = 0
	End Sub

	Public ReadOnly Property Seconds() As Single
		Get
			Dim freq As Long = 0
			QueryPerformanceFrequency(freq)
			Return (CSng(elapsedCount) / CSng(freq))
		End Get
	End Property

	Public Overloads Overrides Function ToString() As String
		Return [String].Format("{0} seconds", Seconds)
	End Function

	<System.Runtime.InteropServices.DllImport("KERNEL32")> _
	Private Shared Function QueryPerformanceCounter(ByRef lpPerformanceCount As Long) As Boolean
	End Function

	<System.Runtime.InteropServices.DllImport("KERNEL32")> _
	Private Shared Function QueryPerformanceFrequency(ByRef lpFrequency As Long) As Boolean
	End Function
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) @Everywhere
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions