Hash table efficiency example

moehdaib

MoeHdaib

Posted on October 3, 2020

Hash table efficiency example

Hash tables is a data structure that can map keys to values which means that it gives every item in a list has key that is used to extract it later.
Its known that hash tables has better performance than normal list but how its differ?

I wrote a code to compare the time it gets for a list to extract an item in reletively big data structure as well as in a hash table.

First, we fill the list and the hash table with 5000000 values.

Alt Text

Then we pick a reandom value between 4 million and 5 million to get the worst case. After that, we calculate the time it takes for the list and the hash table to extract the value.

Alt Text

After we execute the code the results are:

Alt Text

As you can see the difference between the time. The hash table in all the tests took 0 ms but the list took between 34 to 42 ms to extract the desired values.

If you want test the code yourself check my GitHub

💖 💪 🙅 🚩
moehdaib
MoeHdaib

Posted on October 3, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Fundamentals of TDD in C#
csharp Fundamentals of TDD in C#

September 18, 2021

C# Channels
csharp C# Channels

July 31, 2021

Access modifiers in C#
csharp Access modifiers in C#

May 20, 2021

Hash table efficiency example
csharp Hash table efficiency example

October 3, 2020