HashSet vs. List performance

Posted by Michael Damatov on Stack Overflow See other posts from Stack Overflow or by Michael Damatov
Published on 2008-09-29T21:24:15Z Indexed on 2010/05/06 3:48 UTC
Read the original article Hit count: 582

Filed under:
|
|
|
|

It's clear that a search performance of the generic HashSet<T> class is higher than of the generic List<T> class. Just compare the hash-based key with the linear approach in the List<T> class.

However calculating a hash key may itself take some CPU cycles, so for a small amount of items the linear search can be a real alternative to the HashSet<T>.

My question: where is the break-even?

To simplify the scenario (and to be fair) let's assume that the List<T> class uses the element's Equals() method to identify an item.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about Performance