Is there a performance difference between these two algorithms for shuffling an IEnumerable?

后端 未结 3 541
借酒劲吻你
借酒劲吻你 2020-12-18 09:02

These two questions give similar algorthims for shuffling an IEnumerable:

  • C#: Is using Random and OrderBy a good shuffle algorithm?
  • Can you enumerate
3条回答
  •  暖寄归人
    2020-12-18 09:10

    The second version will probably be a bit slower because of RemoveAt. Lists are really arrays that grow when you add elements to them, and as such, insertion and removal in the middle is slow (in fact, MSDN states that RemoveAt has an O(n) complexity).

    Anyway, the best would be to simply use a profiler to compare both methods.

提交回复
热议问题