diff --git a/tests/perf-1.1.6.ps1 b/tests/perf-1.1.6.ps1 index c0dca92..bdbb0d9 100644 --- a/tests/perf-1.1.6.ps1 +++ b/tests/perf-1.1.6.ps1 @@ -1,11 +1,80 @@ -$func = 'https://gist.githubusercontent.com/santisq/bd3d1d47c89f030be1b4e57b92baaddd/raw/aa78870a9674e9e4769b05e333586bf405c1362c/Measure-Expression.ps1' -Invoke-RestMethod $func | Invoke-Expression +function Measure-Expression { + [CmdletBinding()] + [Alias('measureme', 'time')] + param( + [Parameter(Mandatory, Position = 0)] + [hashtable] $Tests, + + [Parameter()] + [int32] $TestCount = 5, + + [Parameter()] + [switch] $OutputAllTests, + + [Parameter()] + [hashtable] $Parameters + ) + + end { + $allTests = 1..$TestCount | ForEach-Object { + foreach ($test in $Tests.GetEnumerator()) { + $sb = if ($Parameters) { + { & $test.Value @Parameters } + } + else { + { & $test.Value } + } + + $now = [datetime]::Now + $null = $sb.Invoke() + $span = [datetime]::Now - $now + + [pscustomobject]@{ + TestRun = $_ + Test = $test.Key + TimeSpan = $span + } + + [GC]::Collect() + [GC]::WaitForPendingFinalizers() + } + } | Sort-Object TotalMilliseconds + + $average = $allTests | Group-Object Test | ForEach-Object { + $avg = [Linq.Enumerable]::Average([long[]] $_.Group.TimeSpan.Ticks) + + [pscustomobject]@{ + Test = $_.Name + Average = $avg + } + } | Sort-Object Average + + $average | Select-Object @( + 'Test' + @{ + Name = "Average ($TestCount invocations)" + Expression = { [timespan]::new($_.Average).ToString('hh\:mm\:ss\.fff') } + } + @{ + Name = 'RelativeSpeed' + Expression = { + $relativespeed = $_.Average / $average[0].Average + [math]::Round($relativespeed, 2).ToString() + 'x' + } + } + ) + + if ($OutputAllTests.IsPresent) { + $allTests + } + } +} $modulePath = Convert-Path $PSScriptRoot\..\output\PSADTree -Measure-Expression @{ - 'v1.1.6-pwsh-7' = { pwsh -File $PSScriptRoot\perfCode.ps1 $modulePath } - 'v1.1.6-pwsh-5.1' = { powershell -File $PSScriptRoot\perfCode.ps1 $modulePath } - 'v1.1.5-pwsh-7' = { pwsh -File $PSScriptRoot\perfCode.ps1 PSADTree } - 'v1.1.5-pwsh-5.1' = { powershell -File $PSScriptRoot\perfCode.ps1 PSADTree } +Measure-Expression -TestCount 5 @{ + 'PSADTree v1.1.6-pwsh-7' = { pwsh -File $PSScriptRoot\perfCode.ps1 $modulePath } + 'PSADTree v1.1.6-pwsh-5.1' = { powershell -File $PSScriptRoot\perfCode.ps1 $modulePath } + 'PSADTree v1.1.5-pwsh-7' = { pwsh -File $PSScriptRoot\perfCode.ps1 PSADTree } + 'PSADTree v1.1.5-pwsh-5.1' = { powershell -File $PSScriptRoot\perfCode.ps1 PSADTree } } diff --git a/tests/perfCode.ps1 b/tests/perfCode.ps1 index 0c219fe..dea448a 100644 --- a/tests/perfCode.ps1 +++ b/tests/perfCode.ps1 @@ -5,7 +5,6 @@ Import-Module $pathOrName Write-Host "Running PSADTree v$((Get-Module PSADTree).Version)" $objects = Get-ADObject -LDAPFilter '(|(objectClass=group)(objectClass=user))' -0..3 | ForEach-Object { - $objects | Where-Object ObjectClass -EQ group | Get-ADTreeGroupMember -Recursive -ShowAll - $objects | Get-ADTreePrincipalGroupMembership -Recursive -ShowAll -} +$objects = 0..15 | ForEach-Object { $objects } +$objects | Where-Object ObjectClass -EQ group | Get-ADTreeGroupMember -Recursive -ShowAll +$objects | Get-ADTreePrincipalGroupMembership -Recursive -ShowAll