Created
March 26, 2012 16:48
Revisions
-
jpoehls revised this gist
Mar 30, 2012 . 2 changed files with 22 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,11 @@ PS> time { ping -n 1 google.com } -Samples 10 -Silent .......... Avg: 62.1674ms Min: 56.9945ms Max: 87.9602ms PS> time { ping -n 1 google.com } -Samples 10 -Silent -Long .......... Avg: 00:00:00.0612480 Min: 00:00:00.0572167 Max: 00:00:00.0765762 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ function Measure-Command2 ([ScriptBlock]$Expression, [int]$Samples = 1, [Switch]$Silent, [Switch]$Long) { <# .SYNOPSIS Runs the given script block and returns the execution duration. @@ -31,9 +31,18 @@ function Measure-Command2 ([ScriptBlock]$Expression, [int]$Samples = 1, [Switch] $stats = $timings | Measure-Object -Average -Minimum -Maximum -Property Ticks # Print the full timespan if the $Long switch was given. if ($Long) { Write-Host "Avg: $((New-Object System.TimeSpan $stats.Average).ToString())" Write-Host "Min: $((New-Object System.TimeSpan $stats.Minimum).ToString())" Write-Host "Max: $((New-Object System.TimeSpan $stats.Maximum).ToString())" } else { # Otherwise just print the milliseconds which is easier to read. Write-Host "Avg: $((New-Object System.TimeSpan $stats.Average).TotalMilliseconds)ms" Write-Host "Min: $((New-Object System.TimeSpan $stats.Minimum).TotalMilliseconds)ms" Write-Host "Max: $((New-Object System.TimeSpan $stats.Maximum).TotalMilliseconds)ms" } } Set-Alias time Measure-Command2 -
jpoehls revised this gist
Mar 26, 2012 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ PS> time { ping -n 1 google.com } -Samples 10 -Silent .......... Avg: 00:00:00.0705483 Min: 00:00:00.0648462 Max: 00:00:00.1081890 -
jpoehls revised this gist
Mar 26, 2012 . 1 changed file with 32 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,14 +1,39 @@ function Measure-Command2 ([ScriptBlock]$Expression, [int]$Samples = 1, [Switch]$Silent) { <# .SYNOPSIS Runs the given script block and returns the execution duration. Discovered on StackOverflow. http://stackoverflow.com/questions/3513650/timing-a-commands-execution-in-powershell .EXAMPLE Measure-Command2 { ping -n 1 google.com } #> $timings = @() do { $sw = New-Object Diagnostics.Stopwatch if ($Silent) { $sw.Start() $null = & $Expression $sw.Stop() Write-Host "." -NoNewLine } else { $sw.Start() & $Expression $sw.Stop() } $timings += $sw.Elapsed $Samples-- } while ($Samples -gt 0) Write-Host $stats = $timings | Measure-Object -Average -Minimum -Maximum -Property Ticks Write-Host "Avg: $((New-Object System.TimeSpan $stats.Average).ToString())" Write-Host "Min: $((New-Object System.TimeSpan $stats.Minimum).ToString())" Write-Host "Max: $((New-Object System.TimeSpan $stats.Maximum).ToString())" } Set-Alias time Measure-Command2 -
jpoehls created this gist
Mar 26, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ function Measure-ExecutionTime ($cmd) { <# .SYNOPSIS Runs the given script block and returns the execution duration. Discovered on StackOverflow. http://stackoverflow.com/questions/3513650/timing-a-commands-execution-in-powershell .EXAMPLE Measure-ExecutionTime { ping -n 1 google.com } #> $sw = [Diagnostics.Stopwatch]::StartNew() & $cmd $sw.Stop() $sw.Elapsed.ToString() }