Benchmarking VBA Code

后端 未结 4 1381
日久生厌
日久生厌 2020-11-29 01:12

What is considered the most accurate way to benchmark VBA code (in my case, I am testing code in Excel)? Are there any other techniques for benchmarking code besides the 2 b

4条回答
  •  清酒与你
    2020-11-29 02:05

    Interesting question. This is not really a full answer but this is too long to be posted as a comment.
    What i use is this kind of procedure:

    Option Explicit
    Public Time As Double
    Sub Chrono()
    If Time = 0 Then
        Time = Now()
    Else
        MsgBox "Total time :" & Application.Text(Now() - _
            Time, "mm:ss") & "."  'or whatever if not a msgbox
        Time = 0
    End If
    End Sub
    

    That way, you can put your code wherever you want and only have to call it twice (for instance):

    If C_DEBUG Then Call Chrono
    

    At the beginning and at the end of the part of code you want to test.

    Yet, i would say there is no real "accurate" method because it also depends on what is running on your computer. I'd say these methods would mostly help telling which code is better than another.

提交回复
热议问题