C# fastest intersection of 2 sets of sorted numbers

前端 未结 5 1428
傲寒
傲寒 2020-12-28 10:00

I\'m calculating intersection of 2 sets of sorted numbers in a time-critical part of my application. This calculation is the biggest bottleneck of the whole application so I

5条回答
  •  感情败类
    2020-12-28 10:03

    You're using a rather inefficient Linq method for this sort of task, you should opt for Intersect as a starting point.

    var intersection = firstSet.Intersect(secondSet);
    

    Try this. If you measure it for performance and still find it unwieldy, cry for further help (or perhaps follow Jon Skeet's approach).

提交回复
热议问题