Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

no improvements on the following PLINQ code

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

like image 528
Matt Avatar asked Dec 22 '25 23:12

Matt


1 Answers

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.

like image 103
Henk Holterman Avatar answered Dec 24 '25 14:12

Henk Holterman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!