C# Parallel Vs. Threaded code performance

前端 未结 4 1281
耶瑟儿~
耶瑟儿~ 2021-02-14 03:19

I\'ve been testing the performance of System.Threading.Parallel vs a Threading and I\'m surprised to see Parallel taking longer to finish tasks than threading. I\'m sure it\'s d

4条回答
  •  没有蜡笔的小新
    2021-02-14 04:14

    It's logical :-)

    That would be the first time in history that addition of one (or two) layers of code improved performance. When you use convenience libraries you should expect to pay the price. BTW you haven't posted the numbers. Got to publish results :-)

    To make things a bit more failr (or biased :-) for the Parallel-s, convert the list into array.

    Then to make them totally unfair, split the work on your own, make an array of just 10 items and totally spoon feed actions to Parallel. You are of course doing the job that Parallel-s promised to do for you at this point but it's bound to be an interesting number :-)

    BTW I just read that Reed's blog. The partitioning used in this question is what he calls the most simple and naive partitioning. Which makes it a very good elimination test indeed. You still need to check the zero work case just to know if it's totally hosed.

提交回复
热议问题