Last active
June 16, 2023 11:34
-
-
Save trackd/fd7c7cb9d25d63e7f78197c71d2bc2e2 to your computer and use it in GitHub Desktop.
Hashtable measurements
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
<# | |
some testing results: | |
machine1 | |
.\group-object-example.ps1 | |
PS 7.3.4 | |
Foreach: 0.0210048 | |
Group: 0.1844798 | |
.\group-object-example.ps1 | |
PS 5.1.22621.1778 | |
Foreach : 0.0373328 | |
Group : 62.6519559 | |
machine2 | |
.\group-object-example.ps1 | |
PS 5.1.14393.5582 | |
Foreach : 0.5106424 | |
Group : 111.8423285 | |
.\group-object-example.ps1 | |
PS 7.3.4 | |
Foreach : 0.0606677 | |
Group : 0.5708983 | |
#> | |
$test = 1..30000 | ForEach-Object { | |
Get-Random | |
} | |
$hash = Measure-Command -Expression { | |
$hashtable = @{} | |
foreach ($item in $test) { | |
$hashtable[$item] = $item | |
} | |
} | |
$group = Measure-Command -Expression { | |
$grouphash = $test | Group-Object -AsHashTable | |
} | |
Write-Output "PS $($PSVersionTable.PSVersion.ToString()) `nForeach`t: $($hash.TotalSeconds) `nGroup`t: $($group.totalseconds)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment