I will use a Dictionary in a .NET project to store a large number of objects. Therefore I decided to use a GUID-string as a key, to ensure unique keys for each object.
Does a large key such as a GUID (or even larger ones) decrease the performance of a Dictionary, e.g. for retrieving an object via its key?
Thanks, Andrej
I would recommend using an actual Guid
rather than the string representation of the Guid
. Yes, when comparing strings the length does affect the number of operations required, since it has to compare the strings character-by-character (at a bare minimum; this is barring any special options like IgnoreCase
). The actual Guid
will give you only 16 bytes to compare rather than the minimum of 32 in the string
.
That being said, you are very likely not going to notice any difference...premature optimization and all that. I would simply go for the Guid
key since that's what the data is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With