VB6中定时功能/测量性能的最佳方法是什么?

时间:2022-04-11 20:23:24

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?

如果我只是想快速测量特定功能的使用时间,我可以调用什么来获得准确的时序?鉴于VB6定时函数的精度不高,您调用的是Windows API函数吗?

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

您还可以通过其他方式衡量应用程序性能?您推荐的是否有任何第三方工具?

3 个解决方案

#1


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

我通常使用Windows hihg分辨率性能计数器。查看QueryPerformanceCounter和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.

通常我有一个简单的类,其构造函数和析构函数调用QueryPerformanceCounter,然后将差异添加到运行总计。

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.

对于工具,请查看devpartner。虽然它运行良好,但检测大量代码会使我的应用程序运行速度极慢。我通常发现我希望只在一两个函数上获得精确的时序,所以我经常最终使用性能计数器函数而不是使用devpartner。

#2


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

#3


VB Watch is another tool you might want to consider.

VB Watch是您可能想要考虑的另一个工具。

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.

当您可以隔离代码的可疑区域时,这些东西是最通用的。许多此类工具允许您将代码检测的范围限制为模块或单个过程,或将监视限制到过程而不是语句级别。这有助于减少与整个程序的逐行仪器相关的一些痛苦。

#1


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

我通常使用Windows hihg分辨率性能计数器。查看QueryPerformanceCounter和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.

通常我有一个简单的类,其构造函数和析构函数调用QueryPerformanceCounter,然后将差异添加到运行总计。

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.

对于工具,请查看devpartner。虽然它运行良好,但检测大量代码会使我的应用程序运行速度极慢。我通常发现我希望只在一两个函数上获得精确的时序,所以我经常最终使用性能计数器函数而不是使用devpartner。

#2


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

#3


VB Watch is another tool you might want to consider.

VB Watch是您可能想要考虑的另一个工具。

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.

当您可以隔离代码的可疑区域时,这些东西是最通用的。许多此类工具允许您将代码检测的范围限制为模块或单个过程,或将监视限制到过程而不是语句级别。这有助于减少与整个程序的逐行仪器相关的一些痛苦。