Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Has got any real benefit of PLINQ?

Tags:

c#

plinq

Recently I made a couple of measures about Linq and Plinq. I can't see in which situation has a real significant benefit of Plinq.

I've found many examples such as:

Enumerable.Range(0, 10000).AsParallel().ForAll(_ => Thread.Sleep(50000));

This is totally useless example, because it can be parallized with degree of 10000 and yes then will be faster 10000 times, but it's rare in a business application to loop 10000 times and making "IO jobs".

If somebody can mention an example please post it.

Plinq is only available for Linq to Objects and Linq to XML. Not suggested to use it in application which runs on webserver(it has own thread management). So our opportunities are reduced to desktop applications which have multiple cores.

Usually I write linq queries which runs sequentially in fractions of a second. If I parallize it and it really will run parallel then will be faster, but who cares? I think it is still fast enough. The end user won't see any difference.

I can imagine an example when somebody gets all data from DB and running query in memory. Then maybe it's useful, but it's a wrong design.

TPL is a good stuff for asyncron programming, but I'm still not sure Plinq is a useful tool.

Does anybody have positive experience about that?

like image 361
speti43 Avatar asked Dec 17 '13 09:12

speti43


1 Answers

The key scenario in which you get benefit from PLINQ is something like this:

int[] src = Enumerable.Range(0, 100).ToArray();
var query = src.AsParallel()
               .Select(x => ExpensiveFunc(x));

And you do get real benefits.

See the article here for more details on when it's useful.

I've seen benefits when, for example, I'm trying to evaluate an expensive iterative numerical method in order to compute a series of Y values from a set of X points for graphing.

like image 99
Baldrick Avatar answered Oct 09 '22 00:10

Baldrick