Average Rating:

3.50 by 3 users.

43 Downloads, 191 Views

1 Comment(s)

run-event10.ps1

By: gmb 22 Apr 2011 03:58 AM UTC in the category: Beginner Event 10

Description:

Beginner event 10
$L = 5  #number of iterations
$T = 5  #number of seconds to wait 
$Sum = New-Object System.TimeSPan
for ($i = 1; $i -le $L; $i++)
{
   $b = New-Object System.TimeSPan
   $b = Measure-Command {Start-Sleep -s $T}
   $Sum += $b.Ticks
}
$a = [Timespan]::FromTicks( $Sum.Ticks / $L )
$c = "Average time of $L runs of $T seconds is $a milliseconds"
Write-Host "$c"
Top

Comments:

4/22/2011 4:01 AM
interesting script. You do not need to use .NET classes for this, you can do everything using cmdlets. But still it meets needs of the event. Avoid using write-host unless you have a need to do so.