-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
needs-triageWaiting - Needs triageWaiting - Needs triage
Description
Type of issue
Missing information
Feedback
TypeSafe Collections
PowerShell is a loosely language by nature which often makes life easier but where it concerns (list) collections you might consider to use a TypeSafe collections knowing that they consume less memory and are about 25% faster where it comes to methods as e.g. Add():
$Stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
$ListInt = [System.Collections.Generic.List[int]]::new()
for ($i = 0; $i -lt 1000000; $i++) {
$ListInt.Add($i)
}
$Stopwatch.Stop()
Write-Host "Time taken to add 1,000,000 integers to List[int]: $($Stopwatch.Elapsed.TotalMilliseconds) ms"
$Stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
$ListObject = [System.Collections.Generic.List[Object]]::new()
for ($i = 0; $i -lt 1000000; $i++) {
$ListObject.Add($i)
}
$Stopwatch.Stop()
Write-Host "Time taken to add 1,000,000 integers to List[Object]: $($Stopwatch.Elapsed.TotalMilliseconds) ms"Page URL
Content source URL
Author
Platform Id
319d7280-c701-6893-7caf-ea95ae00e437
Document Id
9818d91b-8c5f-337a-f5e1-7a40abd5fd1a
Metadata
Metadata
Assignees
Labels
needs-triageWaiting - Needs triageWaiting - Needs triage