Most of us have heard about how to do parallel programming, using Parallel class (PLINQ), provided in the .NET framework.
In this article, I would like to discuss two things about how parallelism cannot be applied in certain cases.
Below is the simple code, which gets the range of an integer from 1 to 100000 and then uses TPL. It is trying to get the list out of the source, where the numbers are even.
- var source = Enumerable.Range(1, 100000);
- var source2 = Enumerable.Range(1, 100000);
- var evenswithParallel = source.AsParallel().Where(x => x % 2 == 0).ToList();
- var evenswithoutParallel = source2.Where(x => x % 2 == 0).ToList();
- var source = Enumerable.Range(1, 100000);
- var source2 = Enumerable.Range(1, 100000);
- Stopwatch sw = Stopwatch.StartNew();
- var evenswithParallel = source.AsParallel().Where(x => x % 2 == 0).ToList();
- sw.Stop();
- Console.WriteLine("With Parallel "+sw.ElapsedMilliseconds);
- sw = Stopwatch.StartNew();
- var evenswithoutParallel = source2.Where(x => x % 2 == 0).ToList();
- sw.Stop();
- Console.WriteLine("Without Parallel "+sw.ElapsedMilliseconds);



Anu VPosted Aug 22, 2016, 8:38 PM EDT
Nice..
Vivek KumarPosted Aug 21, 2016, 12:47 PM EDT
Nice one.
Ravi KandelPosted Aug 13, 2016, 10:52 PM EDT
Nice
Tapan PatelPosted Aug 12, 2016, 8:28 AM EDT
Thank You Vignesh
Vignesh ManiTOP 100Posted Aug 12, 2016, 8:27 AM EDT
Nice
Tapan PatelPosted Aug 12, 2016, 3:12 AM EDT
Thank you Guys.
Prasanna MuraliPosted Aug 11, 2016, 10:43 PM EDT
Nice share
Rajeev PunhaniPosted Aug 11, 2016, 8:51 PM EDT
Nice.