no improvements on the following PLINQ code

时光怂恿深爱的人放手 提交于 2019-12-10 20:32:34

问题


I do not see any improvements in processing speed using the following code:

IEnumerable<Quote> sortedQuotes = (from x in unsortedQuotes.AsParallel()
                                           orderby (x.DateTimeTicks)
                                           select x);

over the sequential version:

IEnumerable<Quote> sortedQuotes = (from x in unsortedQuotes
                                           orderby (x.DateTimeTicks)
                                           select x);

Am I missing something here? I varied the number of items in the source collections from thousands to several tens of millions and no size showed the Parallel version coming out ahead.

Any tips appreciated. By the way if anyone knows of a faster way to sort more efficiently (given my indicated item variable type (containing a long DateTimeTicks by which the items are sorted in the collection) that would also be appreciate.

Edit: "sorting efficiently" -> As fast as possible.

Thanks


回答1:


According to this page,

If you have a sort in your query, stop-and-go will be used instead because pipelining the output of a sort is wasteful. A sort exhibits extremely high latency [...], and so PLINQ prefers to devote all processing power to completing the sort as quickly as possible.

Your query only contains a Sort, the select doesn't count. So the PLINQ engine will execute it as sequential.

You can only expect some improvement when the sorting is a part of a larger query.



来源:https://stackoverflow.com/questions/10733616/no-improvements-on-the-following-plinq-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!