问题
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