Dictionary performance based on key length

If I had a dictionary with a huge key, would it make the search much slower?

What I mean by huge key:

{"THIS IS A HUGE KEY THAT IS VERY LONG1" : 1, "THIS IS A HUGE KEY THAT IS VERY LONG2" : 2}

Would a key, which is a string of length 300, be significantly slower than a key of length 3? Since dictionary searchO(1)

+3


source to share


1 answer


It is not difficult to verify this empirically,

For cpython, the answer is no, it shouldn't take any longer. Other implementations can recalculate the hash on demand. You will have to learn this yourself if you are not using cpython



If the keys are large and numerous enough, you may notice effects due to processor cache and swap.

+2


source







All Articles