代码之家  ›  专栏  ›  技术社区  ›  Gavin

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

  •  4
  • Gavin  · 技术社区  · 17 年前

    如果我只想快速测量一个特定的函数需要多长时间,我可以调用什么来获得一个准确的时间?考虑到vb6定时函数的精度不高,您是否改为调用Windows API函数?

    您以什么其他方式衡量应用程序性能?您有没有推荐的第三方工具?

    3 回复  |  直到 12 年前
        1
  •  4
  •   Stephen Nutt    17 年前

    我通常使用Windows高分辨率性能计数器。退房 QueryPerformanceCounter QueryPerfomanceFrequency

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

    对于工具,请签出 devpartner . 虽然它工作得很好,但是检测代码的重要部分会使我的应用程序运行得异常缓慢。我通常会发现我只想在一个或两个函数上获得精确的时间安排,所以我经常使用性能计数器函数,而不使用devpartner。

        2
  •  4
  •   Kris Erickson    12 年前

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

    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
    
        3
  •  1
  •   Bob    17 年前

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

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