Tuesday, June 15, 2010

Measuring Execution time with powershell

This is an easy one - use measure-command CommandLet

measure-command {
# do your long running action in here, like loading a file
@file = get-content "c:\MyFile.txt"
}

Output Looks like this:
Days : 0
Hours : 0
Minutes : 0
Seconds : 1
Milliseconds : 638
Ticks : 16386148
TotalDays : 1.89654490740741E-05
TotalHours : 0.000455170777777778
TotalMinutes : 0.0273102466666667
TotalSeconds : 1.6386148
TotalMilliseconds : 1638.6148

You can also format the output by piping the output into the Filter-Table commandlet

measure-command {
# do your long running action in here, like loading a file
@file = get-content "c:\MyFile.txt"
} | ft -Property Hours, Minutes, Seconds, Milliseconds

Output Looks like this:
Hours Minutes Seconds Milliseconds
----- ------- ------- ------------
0 0 1 567

No comments:

Post a Comment