Fine-grained timer for VBScript performance measurements
I'm doing some performance m开发者_StackOverflow中文版easurements 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.
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.
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"
精彩评论