Performance - using Guid object or Guid string as Key

后端 未结 3 1646
遥遥无期
遥遥无期 2020-12-05 03:52

When using a Guid as an index for a Dictionary, is it better to use the Guid object, or the string representation of the Guid?

3条回答
  •  暖寄归人
    2020-12-05 04:40

    The collections are fairly small, but they get iterated lots of times

    If you are iterating, there are no key to key comparisons. If you are adding/modifying or looking up by key, then keys will be hashed and the hashes compared; only if the hashes are equal will the keys be compared.

    Therefore, unless you are performing a lot of key based operations on huge dictionaries with many hash collisions the speed of key to key comparisons will not be a major factor.

提交回复
热议问题