5

I'm doing some performance measurements in VBScript. I want to measure how fast my algorithm performs

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

This gives me the time in seconds. If one algorithm results in a 1 second execution time and another in 2 seconds, this will hardly give me any useful information. I need to blow up the problem size to something that takes a minute to execute.

Does anybody know of a way to do these kinds of measurements in VBScript, but then more fine-grained. Something that introduces milliseconds for example.

I have a feeling that there must be a solution in WMI.

1
  • 3
    You need to run your algorithms in a loop hundreds or even thousands of times. That not only compensates for a lower resolution timer, but also prevents random "noise" from clouding your findings. Mar 8, 2011 at 10:08

2 Answers 2

7

You could use the VBScript Timer function to get the elapsed time in milliseconds:

The Timer function returns the number of seconds and milliseconds, since 12:00 AM.

2
  • 1
    Yes, it's as simple as that. I chose "timer" as a tag, but did not have the wits to check the VBScript documentation for a function with that name.
    – mgr326639
    Mar 8, 2011 at 17:25
  • 3
    Be aware that the resolution of the Timer function isn't exactly one millisecond. I can't find any documentation on this, but experimentally on my Win7 64-bit computer, the resolution is ~8ms. At work, on WinXP, it's about 15ms. Mar 9, 2011 at 5:51
1

If you are working in HP QuickTest Pro, here are two more methods that you are afforded:

Timers will give a result (in milliseconds) that you can store in a variable

MercuryTimers("timerName").Start
Wait 2
Msgbox "Time is ticking..."
MercuryTimers("timerName").Stop
Msgbox "Elapsed time is: " & MercuryTimers("timerName").Elapsedtime & " milliseconds"

Transaction times show up in the QTP results / report

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.