PerformanceBenchmark.psm1
Function PerformanceTestArguments { param ( [Parameter(Mandatory=$true)] [ScriptBlock] $Expression, [Parameter(Mandatory=$true)] [Object[]] $Arguments, [Parameter(Mandatory=$false)] [int] $Count, [Parameter(Mandatory=$false)] [string] $Title ) if($Count -eq $null -or $Count -le 0) { $Count = 1 } $resultsList = New-Object System.Collections.Generic.LinkedList[long] for($i=0;$i -lt $Count;$i=$i+1) { foreach($argument in $Arguments) { $stopwatch = [System.Diagnostics.Stopwatch]::StartNew() Invoke-Command $Expression -ArgumentList $argument $stopwatch.Stop() $resultsList.AddFirst($($stopwatch.Elapsed.TotalMilliseconds)) | Out-Null } } $result = $($resultsList | Measure-Object -Maximum -Minimum -Average -Sum) if($Title -ne $null) { $result.Property = $Title } return $result } Function PerformanceTest { param ( [Parameter(Mandatory=$true)] [ScriptBlock] $Expression, [Parameter(Mandatory=$false)] [int] $Count, [Parameter(Mandatory=$false)] [string] $Title ) if($Count -eq $null -or $Count -le 0) { $Count = 1 } $resultsList = New-Object System.Collections.Generic.LinkedList[long] for($i=0;$i -lt $Count;$i=$i+1) { $stopwatch = [System.Diagnostics.Stopwatch]::StartNew() $Expression.Invoke($argument) $stopwatch.Stop() $resultsList.AddFirst($($stopwatch.Elapsed.TotalMilliseconds)) | Out-Null } $result = $($resultsList | Measure-Object -Maximum -Minimum -Average -Sum) if($Title -ne $null) { $result.Property = $Title } return $result } Export-ModuleMember -Function PerformanceTestArguments Export-ModuleMember -Function PerformanceTest |