Optimizing Lookups: Dictionary key lookups vs. Array index lookups

前端 未结 7 1197
忘了有多久
忘了有多久 2020-12-15 03:40

I\'m writing a 7 card poker hand evaluator as one of my pet projects. While trying to optimize its speed (I like the challenge), I was shocked to find that the performance o

7条回答
  •  星月不相逢
    2020-12-15 03:49

    Is this type of behavior expected (performance decrease by a factor of 8)?

    Why not? Each array lookup is almost intantaneous/negligeable, whereas a dictionary lookup may need at least an extra subroutine call.

    The point of their both being O(1) means that even if you have 50 times more items in each collection, the performance decrease is still only a factor of whatever it is (8).

提交回复
热议问题