首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在VB6中计时函数/测量性能的最佳方法是什么?

在VB6中计时函数/测量性能的最佳方法是什么?
EN

Stack Overflow用户
提问于 2009-04-20 02:03:22
回答 3查看 3.5K关注 0票数 4

如果我只想快速测量一个特定函数所用的时间,我可以调用什么来获得准确的时间?鉴于VB6计时函数的精度不高,您是否可以调用Windows API函数呢?

您还可以通过哪些其他方式来衡量应用程序性能?你有没有推荐的第三方工具?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2009-04-20 02:09:42

我通常使用Windows hihg分辨率性能计数器。查看QueryPerformanceCounterQueryPerfomanceFrequency

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

有关工具,请查看devpartner。虽然它工作得很好,但插装很大一部分代码会使我的应用程序运行慢得让人无法忍受。我通常发现我希望在一两个函数上获得精确的时间,所以我经常使用性能计数器函数,而不是使用devpartner。

票数 4
EN

Stack Overflow用户

发布于 2009-04-20 15:14:58

我使用高性能的多媒体定时器。下面是调试性能分析库的一个片段。

代码语言:javascript
复制
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

用法:

代码语言:javascript
复制
   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
票数 4
EN

Stack Overflow用户

发布于 2009-04-20 03:38:05

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

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/766596

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档