I use the the high performance multimedia timers. Here is a snippet of a debug
profiling library.
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Private Declare Function timeBeginPeriod Lib "winmm.dll" (ByVal uPeriod As Long) As Long
Private Declare Function timeEndPeriod Lib "winmm.dll" (ByVal uPeriod As Long) As Long
Private mlTimeStarted As Long
Public Sub StartTimer()
10 Call timeBeginPeriod()
20 mlTimeStarted = timeGetTime()
End Sub
Public Function GetTimeElaspsed() As Long
10 GetTimeElaspsed = timeGetTime() - mlTimeStarted
End Function
Public Sub EndTimer(Optional lPeriod As Long = 1)
Debug.Assert lPeriod < 10
10 Call timeEndPeriod
20 mlTimeStarted = 0
End Sub
Public Sub DebugProfileStop()
10 Call EndTimer
End Sub
Public Sub DebugProfileReset()
10 If mlTimeStarted > 0 Then
20 EndTimer
30 End If
40 Call StartTimer
End Sub
Public Sub DebugProfile(sText As String)
10 Debug.Print "Debug " & sText & " : " & CStr(GetTimeElaspsed(2))
End Sub
Usage:
DebugProfileReset
DebugProfile("Before Loop")
For index = 0 to 10000
DebugProfile("Before Call To Foo")
Foo
DebugProfile("Before Call To Bar")
Bar
DebugProfile("Before Call To Baz")
Baz
Next inde
DebugProfile("After Loop")
DebugProfileStop