Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way of timing functions / measuring performance in VB6?

If I just want to do a quick measurement of how long a particular function is taking, what can I call to get an accurate timing? Given that the VB6 timing functions aren't high precision, are there Windows API functions you call instead?

In what other ways do you measure application performance? Are there any third-party tools that you recommend?

like image 331
Gavin Avatar asked Jan 23 '23 16:01

Gavin


2 Answers

I typically use the Windows hihg resolution performance counters. Check out QueryPerformanceCounter and QueryPerfomanceFrequency

Typically I have a simple class whose constructor and destructor place a call to QueryPerformanceCounter and then add the difference to a running total.

For tools check out devpartner. While it works well, instrumenting significant portions of code makes my application run unbearably slow. I typically find I wish to get precise timing on just one or two functions so I frequently end up using the performance counter functions and not using devpartner.

like image 169
Stephen Nutt Avatar answered Jan 26 '23 06:01

Stephen Nutt


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(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

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 index
   DebugProfile("After Loop")
   DebugProfileStop
like image 24
Kris Erickson Avatar answered Jan 26 '23 06:01

Kris Erickson