View Single Post
Old 08-31-2006   #3 (permalink)
Alex K. Angelopoulos [MVP]


 
 

Re: Testing object arrays using Compare-Object and -contains


"Jouko Kynsijärvi" <jouko.kynsijarvi@nospam.nospam> wrote in message
news:ujV822TzGHA.4232@TK2MSFTNGP05.phx.gbl...
> Alex K. Angelopoulos [MVP] wrote:
>> I'm having trouble finding a simple scheme for getting all objects
>> which are members of a set B but not also members of another set A.


> Here is another approach:
>
> $a=@(gsnp | ?{ !$_.isdefault }); $a+=@(gsnp -r)
> $a | group name | ?{ $_.count -eq 1} | asnp
>
>> Compare-Object also takes a while to run; this is not really the kind
>> of thing it was specifically designed to do.

>
> In my testing Get-PSSnapin without -r is the slow one:
> [~] (measure-command { get-pssnapin }).milliseconds
> 714
> [~] (measure-command { get-pssnapin -r}).milliseconds
> 7
>
> ...Compare-Object on the other hand is quite fast:
> [~] $a = 1..500; $b = 5..505
> [~] (measure-command { compare-object $a $b }).milliseconds
> 61


Whoops.
I had a spin-up pause because my Compare-Object had to evaluate Get-PSSnapin
before executing. Duh! :|


My System SpecsSystem Spec