Created
March 27, 2018 22:09
-
-
Save pezhore/e8fef050b5d426dc34902088944f9a3c to your computer and use it in GitHub Desktop.
This file contains 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 characters
function Get-Benchmark { | |
[CmdletBinding()] | |
param( | |
$ScriptBlock, | |
[Int32] $Iterations | |
) | |
begin {} | |
process { | |
$AllTimespans = [System.Collections.ArrayList]@() | |
1..$Iterations | Foreach-Object{ | |
$ProgressSplat = @{ | |
Activity = "Iterating Over ScriptBlock" | |
Status = "Current Iteration ($( $_ ) of $Iterations)" | |
PercentComplete = ( $_ / $Iterations ) * 100 | |
} | |
Write-Progress @ProgressSplat | |
Remove-Variable -Name Start -ErrorAction SilentlyContinue | |
$Start = Get-Date | |
Invoke-Command -ScriptBlock $ScriptBlock | Out-Null | |
$AllTimespans.Add((New-TimeSpan $Start)) | Out-Null | |
} | |
} | |
end { | |
Write-Debug "Anything Else?" | |
$Average = [String][Timespan]::FromTicks(([Math]::Round(($AllTimespans.ticks | Measure-Object -average | Select-Object -Expand Average)))) | |
$Min = [String][Timespan]::FromTicks(([Math]::Round(($AllTimespans.ticks | Measure-Object -Minimum | Select-Object -Expand Minimum)))) | |
$Max = [String][Timespan]::FromTicks(([Math]::Round(($AllTimespans.ticks | Measure-Object -Maximum | Select-Object -Expand Maximum)))) | |
Write-Output "Min: $Min" | |
Write-Output "Avg: $Average" | |
Write-output "Max: $Max" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment