Average Rating:

2.50 by 2 users.

26 Downloads, 62 Views

1 Comment(s)

Get-StartSleepTime

By: Dennis W 21 Apr 2011 06:41 PM UTC in the category: Beginner Event 10

Description:

Test accuracy of Start-Sleep command.
<#
	.SYNOPSIS
		Test accuracy of Start-Sleep command.
	
	.DESCRIPTION
		The Get-StartSleepTime script
	
	.EXAMPLE
		Get-StartSleepTime 5 3

	.NOTES
		Name: Get-StartSleepTime.ps1
		Author: Dennis Wood
		Created: 2011-04-21
		LastEdit: 2011-01-21 13:37
		Version: 1.0.0
		
		#Requires -Version 2.0
		
#>

[CmdletBinding()]
	param (
		[Parameter(Position=0, Mandatory=$false, ValueFromPipeline=$true)]
		[Int]$repeat,
		
		[Parameter(Position=1, Mandatory=$false, ValueFromPipeline=$true)]
		[Int]$sleeptime
		
	)
	
	process {
		If ($repeat -eq 0) {
			$repeat = 5
		}
		If ($sleeptime -eq 0) {
			$sleeptime = 5
		}

		$total = 0
		$i = 1
		while ($i -le $repeat) {
			$begin = Get-Date
			Start-Sleep $sleeptime
			$end = Get-Date
			$difference = $end - $begin
			$total = $total + $difference.TotalMilliseconds
			$i++
		}
		"Average time of $repeat run(s) of $sleeptime second(s) is " + $total/$repeat + " milliseconds"
	}
Top

Comments:

4/21/2011 9:01 PM
One thing that I would suggest you look at is default values for parameter values.

I would also consider looking into measure-command to compare the time differences.