Skip to content

Instantly share code, notes, and snippets.

@evetsleep
Created February 24, 2019 23:01
Show Gist options
  • Save evetsleep/ad9354bac6ae9c970d9d2eef183a9e85 to your computer and use it in GitHub Desktop.
Save evetsleep/ad9354bac6ae9c970d9d2eef183a9e85 to your computer and use it in GitHub Desktop.
$arrayList = New-Object -TypeName System.Collections.Generic.List[int]
0..9999 | ForEach-Object { $arrayList.Add($PSItem) }
$iterations = 1000
$results = New-Object -TypeName System.Collections.Generic.List[PSCustomObject]
1..$iterations | ForEach-Object {
$number = Get-Random -Maximum 9999
$resultObject = [PSCustomObject]@{
whereMethod = (Measure-Command -Expression { $arrayList.where{$PSItem -eq $number} }).Milliseconds
whereObject = (Measure-Command -Expression { $arrayList | Where-Object { $PSItem -eq $number } }).Milliseconds
}
$results.Add($resultObject)
}
[PSCustomObject]@{
Iterations = $results.count
whereMethod = [math]::Round(($results | Measure-Object -Property whereMethod -Average).Average,2)
whereObject = [math]::Round(($results | Measure-Object -Property whereObject -Average).Average,2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment