views:

377

answers:

3

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?

+3  A: 

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.

Stephen Nutt
John Dibling
I found this, pretty useful: http://support.microsoft.com/kb/172338
Gavin Schultz-Ohkubo
+1  A: 

VB Watch is another tool you might want to consider.

These things are most versatile when you can isolate suspect areas of your code. Many tools of this type allow you to limit the coverage of the code instrumentation to modules or individual procedures, or limit monitoring to the procedure rather than statement level. This can help to reduce some of the pain associated with line by line instrumentation of the whole program.

Bob
+2  A: 

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
Kris Erickson
Hmm, really interesting. Looks even a bit more straightforward than using the QueryPerformanceCounter, though I've already implemented a solution that way. Thanks.
Gavin Schultz-Ohkubo
This is also the methodology I use for timing. Simple and works well.
Joe