在VB6中定时功能/测量性能的最佳方式是什么?
问题描述:
如果我只是想快速测量一个特定功能需要多长时间,我可以调用什么来获得准确的时间?鉴于VB6定时功能的精确度不高,是否有您调用的Windows API函数?在VB6中定时功能/测量性能的最佳方式是什么?
您以什么方式衡量应用程序的性能?您有推荐的第三方工具吗?
答
我通常使用Windows hihg分辨率性能计数器。退房QueryPerformanceCounter和QueryPerfomanceFrequency
通常我有一个简单的类,其构造函数和析构函数调用QueryPerformanceCounter,然后将差异添加到运行总数。
工具退房devpartner。虽然它运行良好,但重要的代码部分使我的应用程序运行速度缓慢。我通常会发现我希望在一个或两个函数上获得精确的时序,所以我经常最终使用性能计数器函数,而不是使用devpartner。
答
VB Watch是您可能需要考虑的另一个工具。
这些东西是最通用的,当你可以隔离你的代码的可疑区域。许多此类工具允许您将代码工具的覆盖范围限制为模块或单个过程,或将监控范围限制为过程而非语句级别。这可以帮助减少与整个程序的逐行仪器相关的一些痛苦。
答
我使用高性能的多媒体定时器。这是一个调试 概要分析库的代码片段。
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
用法:
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
任何机会,你可以使用QPC发布VB6代码?我很好奇你将如何去宣布和使用LARGE_INTEGER。我不是“VB人”。 – 2009-04-20 04:23:02
我发现这个,很有用:http://support.microsoft.com/kb/172338 – Gavin 2009-04-20 04:37:53