用于VBScript性能测量的细粒度计时器

时间:2011-03-08 09:53:51

标签: vbscript timer benchmarking

我正在VBScript中进行一些性能测量。我想测量算法的执行速度

t1 = Now()  
doAlotOfWork ()  
t2 = Now()  
MsgBox "Operation took " & DateDiff ("s", t1, t2)  & " seconds."

这给了我几秒钟的时间。如果一个算法导致1秒执行时间而另一个算法导致2秒钟,这几乎不会给我任何有用的信息。我需要将问题大小炸成一段需要一分钟才能执行的东西。

有人知道在VBScript中进行这些测量的方法,但随后更细粒度。例如,引入毫秒的东西。

我觉得WMI必须有解决方案。

2 个答案:

答案 0 :(得分:7)

您可以使用VBScript Timer function来获取经过的时间(以毫秒为单位):

  

Timer函数返回数字   秒和毫秒,因为   凌晨12点。

答案 1 :(得分:1)

如果您使用的是HP QuickTest Pro,则可以使用以下两种方法:

计时器将给出可以存储在变量

中的结果(以毫秒为单位)
MercuryTimers("timerName").Start
Wait 2
Msgbox "Time is ticking..."
MercuryTimers("timerName").Stop
Msgbox "Elapsed time is: " & MercuryTimers("timerName").Elapsedtime & " milliseconds"

交易时间显示在QTP结果/报告中

Services.StartTransaction "transactionName"
Wait 2
Msgbox "Time is ticking..."
Services.EndTransaction "transactionName"