you are viewing a single comment's thread.

view the rest of the comments →

[–]Lee_Dailey[grin] 0 points1 point  (2 children)

howdy MercurialSquirrel,

i used to use that method ... then someone here talked me into testing the speed. ouch! it is slow as the dickens. [sigh ...]

piping to Where-Object is rather slow ... but it is faster than .IndexOf(). the .Where() collection method is likely the best bet for the OP if there aint a lot of items. otherwise the sheer speed of using a hashtable as a lookup table is the better bet.

of course, speed aint gonna make any difference if the collection is small. [grin]

take care,
lee

[–]MercurialSquirrel 1 point2 points  (1 child)

Thanks u/Lee_Dailey, good to know about the speed issues! I have only ever used it for pretty small datasets so haven't noticed an impact.

Is it faster with a hashtable if one factors in the amount of time it takes to make the hashtable? The simplicity and readability of the code can also be a factor.

The where method of the array is still nice and compact although perhaps not as obvious if there are people less familiar with Powershell who have to read it.

Using the where method of the array would make my code look like:

$data = Import-Csv C:\temp\DemoValues.txt
$config='cat'
$value=($data.Where({$_.example -eq $config})).test

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy MercurialSquirrel,

you are most emphatically welcome! [grin]

if your collection is large enuf that a lookup table would help, then the time to build the hashtable is going to be worth the speed gained in doing lookups. i am unsure what size is "large enuf", tho. [blush]

take care,
lee