Average Rating:

4.00 by 4 users.

46 Downloads, 320 Views

2 Comment(s)

TimingIsEverything

By: Joe D. 22 Apr 2011 06:30 AM UTC in the category: Beginner Event 10

Description:

Determine the amount of time a command takes to complete.
$seconds = 5
$iterations = 5
$total = 0
For ($i=1; $i -ile $iterations; $i += 1)
{
$a = get-date -uformat %s
start-sleep $seconds
$b = get-date -uformat %s
$time = ($b-$a)*1000
write-host "Run" $i "took" $time "milliseconds"
$total += $time
}
$average = ($total / $iterations)
write-host "Average time of" $iterations "runs of" $seconds "seconds is" $average "milliseconds"
Top

Comments:

4/22/2011 7:33 AM
Nice script. I like that you report individual runs, and then calculate the averages. Good use of -uformat.
4/25/2011 8:56 AM
Actually hadn't noticed the -uformat for get-date.. I can use that in another script I am doing.. Thanks :)