Skip to content

Instantly share code, notes, and snippets.

@nohwnd
Created January 25, 2019 19:11
Show Gist options
  • Select an option

  • Save nohwnd/2b3316872aa29fadbcfcedfe5ca9fe44 to your computer and use it in GitHub Desktop.

Select an option

Save nohwnd/2b3316872aa29fadbcfcedfe5ca9fe44 to your computer and use it in GitHub Desktop.
list vs arr
$arr = 1..100
$repe = 1..100
Measure-Command {
foreach ($i in $repe) {
$l = New-Object 'System.Collections.Generic.List[Object]'
foreach ($ii in $arr) {
$l.Add($ii)
}
}
$l.count -eq $arr.count
}
Measure-Command {
foreach ($i in $repe) {
$l = @()
foreach ($ii in $arr) {
$l += $ii
}
}
$l.count -eq $arr.count
}
@nohwnd
Copy link
Author

nohwnd commented Jan 25, 2019

New-Object <- super slow, [System.Collections.Generic.List[Object]]@() (v3+) or [System.Collections.Generic.List[Object]]::new() (v5+) is the way to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment