I use high-performance multimedia timers. Here is a fragment 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(Optional lPeriod As Long = 1) 10 Call timeBeginPeriod(lPeriod) 20 mlTimeStarted = timeGetTime() End Sub Public Function GetTimeElapsed() As Long 10 GetTimeElapsed = timeGetTime() - mlTimeStarted End Function Public Sub EndTimer(Optional lPeriod As Long = 1) Debug.Assert lPeriod < 10 10 Call timeEndPeriod(lPeriod) 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(GetTimeElapsed) End Sub
Using:
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 index DebugProfile("After Loop") DebugProfileStop
source share