Hash table efficiency example
MoeHdaib
Posted on October 3, 2020
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.
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.
After we execute the code the results are:
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
Posted on October 3, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.