-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
Description
Type of issue
Missing information
Feedback
Even it is implied in the section Avoid wrapping cmdlet pipelines section and covered in the Everything you wanted to know about PSCustomObject / Legacy approach. Creating PSCustomObject
is a very common use case and the impact of using the New-Object
cmdlet vs [PSCustomObject]@{ ... }
type initiator is quite severe:
Measure-Command {
for ($i = 0; $i -lt 1e6; $i++) {
$resultObject = [PSCustomObject]@{
Name = 'Name'
Path = 'FullName'
}
}
}
Measure-Command {
for ($i = 0; $i -lt 1e6; $i++) {
$resultObject = New-Object -TypeName PSObject -Property @{
Name = 'Name'
Path = 'FullName'
}
}
}
Syntax | Windows PowerShell (5.1) | PowerShell 7.4.5 (Core) |
---|---|---|
New-Object |
90 secondes | 39 secondes |
[PSCustomObject] |
8 secondes | 5 secondes |
I recommend to make a special note in this performance document too.
Page URL
Content source URL
Author
Document Id
9818d91b-8c5f-337a-f5e1-7a40abd5fd1a