Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think the biggest difference you'll see is the performance. Have a look at this blog post:</p> <p><a href="http://powertoe.wordpress.com/2011/03/31/combining-objects-efficiently-use-a-hash-table-to-index-a-collection-of-objects/" rel="nofollow noreferrer">http://powertoe.wordpress.com/2011/03/31/combining-objects-efficiently-use-a-hash-table-to-index-a-collection-of-objects/</a></p> <p>The author ran the following code:</p> <pre><code>$numberofobjects = 1000 $objects = (0..$numberofobjects) |% { New-Object psobject -Property @{'Name'="object$_";'Path'="Path$_"} } $lookupobjects = (0..$numberofobjects) |% { New-Object psobject -Property @{'Path'="Path$_";'Share'="Share$_"} } $method1 = { foreach ($object in $objects) { $object |Add-Member NoteProperty -Name Share -Value ($lookupobjects|?{$_.Path -eq $object.Path} |select -First 1 -ExpandProperty share) } } Measure-Command $method1 |select totalseconds $objects = (0..$numberofobjects) |% { New-Object psobject -Property @{'Name'="object$_";'Path'="Path$_"} } $lookupobjects = (0..$numberofobjects) |% { New-Object psobject -Property @{'Path'="Path$_";'Share'="Share$_"} } $method2 = { $hash = @{} foreach ($obj in $lookupobjects) { $hash.($obj.Path) = $obj.share } foreach ($object in $objects) { $object |Add-Member NoteProperty -Name Share -Value ($hash.($object.path)).share } } Measure-Command $method2 |select totalseconds &lt;# Blog author's output: TotalSeconds ------------ 167.8825285 0.7459279 #&gt; </code></pre> <p>His comment regarding the code results is:</p> <blockquote> <p>You can see the difference in speed when you put it all together. The object method takes 167 seconds on my computer while the hash table method will take under a second to build the hash table and then do the lookup</p> </blockquote> <p>Here are some of the other, more-subtle benefits: <a href="http://blogs.microsoft.co.il/blogs/scriptfanatic/archive/2012/04/13/Custom-objects-default-display-in-PowerShell-3-0.aspx" rel="nofollow noreferrer">http://blogs.microsoft.co.il/blogs/scriptfanatic/archive/2012/04/13/Custom-objects-default-display-in-PowerShell-3-0.aspx</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload