Why is ConcurrentBag so slow in .Net (4.0)? Am I doing it wrong?

后端 未结 11 580
无人及你
无人及你 2020-12-08 04:05

Before I started a project, I wrote a simple test to compare the performance of ConcurrentBag from (System.Collections.Concurrent) relative to locking & lists. I am extr

11条回答
  •  再見小時候
    2020-12-08 04:59

    Because the loop body is small, you could try using the Partitioner class Create method...

    which enables you to provide a sequential loop for the delegate body, so that the delegate is invoked only once per partition, instead of once per iteration

    How to: Speed Up Small Loop Bodies

提交回复
热议问题