Recording how long VBscripts take to run

Quite often it’s useful to have some idea how long scripts are taking to run. A simple way to do that is to use the Timer() function in VBscript.

Near the start of your script record the current value returned by Timer():

'Timestamp at the start of the script
startTime = Timer()

and then near the end take it again:

'Timestamp at the end of the script
endTime = Timer()

You can then work out how long the script took to run between these two points is milliseconds by using:

' Work out how long it took
Duration = Int((endTime-startTime)*1000)

which of course you can then output on completion:

context.SetResult 0,"Completed Successfully. (Script took " & Duration & " ms)"
Tagged ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: