Created
January 25, 2019 19:11
-
-
Save nohwnd/2b3316872aa29fadbcfcedfe5ca9fe44 to your computer and use it in GitHub Desktop.
list vs arr
This file contains hidden or 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
| $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 | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
New-Object<- super slow,[System.Collections.Generic.List[Object]]@()(v3+) or[System.Collections.Generic.List[Object]]::new()(v5+) is the way to go.