Among Find, Single, First, which one is the fastest?

前端 未结 5 1833
庸人自扰
庸人自扰 2020-12-30 23:28

I want to minimize the time needed to retrieve a single unique element from a list. Which one is the fastest method among Find, Single and Fi

5条回答
  •  無奈伤痛
    2020-12-31 00:12

    The fastest (for a large set) would be to have them keyed against a Dictionary and use that.

    Single and First do different things; Single always iterates the entire set, even if it finds it at the start of the list, so First would usually be quicker than Single since it short-circuits.

提交回复
热议问题