Skip to content

Instantly share code, notes, and snippets.

@HCRitter
Created May 23, 2024 22:18
Show Gist options
  • Save HCRitter/aa3429422a690f8b601532b18186b47a to your computer and use it in GitHub Desktop.
Save HCRitter/aa3429422a690f8b601532b18186b47a to your computer and use it in GitHub Desktop.
$TestSize = 500kb
$LargeArrayList = New-Object -TypeName "System.Collections.ArrayList"
$AllTests = foreach($i in (1..$TestSize)){
$Guid = ((New-Guid).ToString())
[PSCustomObject]@{
TestName = 'Out-Null'
TestResult = (Measure-Command {
$LargeArrayList.Add([PSCustomObject]@{
Guid = $Guid
}) | Out-Null
}).TotalMilliseconds
}
[PSCustomObject]@{
TestName = 'void'
TestResult = (Measure-Command {
[void]$LargeArrayList.Add([PSCustomObject]@{
Guid = $Guid
})
}).TotalMilliseconds
}
[PSCustomObject]@{
TestName = '$null'
TestResult = (Measure-Command {
$null = $LargeArrayList.Add([PSCustomObject]@{
Guid = $Guid
})
}).TotalMilliseconds
}
}
$Result = $AllTests | Group-Object -Property TestName | ForEach-Object {
[PSCustomObject]@{
TestName = $_.Name
AverageTime = ($_.Group | Measure-Object -Property TestResult -Maximum -Minimum -Average)
}
}
$Finaloutput = $Result | Select-Object -Property TestName, @{Name='AverageTime';Expression={"{0:N2}" -f $_.AverageTime.Average}}, @{Name='MaximumTime';Expression={"{0:N2}" -f $_.AverageTime.Maximum}}, @{Name='MinimumTime';Expression={"{0:N2}" -f $_.AverageTime.Minimum}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment