Skip to content

Instantly share code, notes, and snippets.

View johannesfk's full-sized avatar
🎯
Focusing

Johannes Farmer Knudsen johannesfk

🎯
Focusing
View GitHub Profile
@johannesfk
johannesfk / Performance.md
Created March 5, 2024 14:45
Hashset vs List in C#

Comparing Performance

Hashsets are generally faster than lists. The major reason this is the case is that no duplicated data is allowed. In the case of a contains operation there is an overhead by using hashsets. This is because a hash needs to be calculated for the item that will be queried. Hashing is an slighty expensive operation, so lists are faster with fewer items because the time to calculate the hash is longer. However, on a certain point hashsets and lists break even and the performance of lists will continue to decrease as more items are added.