Forum Discussion
PS array performance >40K entries
- Nov 10, 2020
Joe_Cauffiel Thanks for the alternative solution. My next step was to switch over to using a HASH array but it still does not explain why .contains is taking 2ms and .where is taking 1000ms when they are both using the same search criteria and scanning through the array. I'm wondering if I am missing an option on the ".where" somehow.
Joe_Cauffiel Hi
I had a small mistake in my code and the HASH solution works great. Thanks for your help
Joe's hash idea looks very useful. I've not yet wrapped my head around Hash tables to be honest but as to why the contains method is so much quicker than the Where method is that the latter has to read each object in the array and read the Userprincipal attribute until it finds an object that where the UPN matches your search string whilst the first method is doing a straight read until it finds that string and then retrieving that object. Probably not the most technically accurate explanation but that's my understanding of it..
- Joe_CauffielNov 17, 2020Copper Contributor
I suspect the ‘contains’ method returns a faster response because it only needs to iterate through the collection until the first match, while the “where” method needs to iterate through the whole collection before it completes. Have you measure the completion times of ‘Contains’ Method where the search item is at the beginning, middle and end of the collection? Is the completion time using the 'contains' method on the last item of collection closer to the time of the 'where' method?
This link has a good primer on Hash Tables.- PeterJ_InobitsNov 18, 2020Iron Contributor
Joe_Cauffiel That is exactly what I was trying to say you just articulated way better than I did..
Thanks for the hash table primer. I will take a look.