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 23, 2016, 12:38 AM
Nice..
Vivek KumarPosted Aug 21, 2016, 4:47 PM
Nice one.
Ravi KandelPosted Aug 14, 2016, 2:52 AM
Nice
Tapan PatelPosted Aug 12, 2016, 12:28 PM
Thank You Vignesh
Vignesh ManiPosted Aug 12, 2016, 12:27 PM
Nice
Tapan PatelPosted Aug 12, 2016, 7:12 AM
Thank you Guys.
Prasanna MuraliPosted Aug 12, 2016, 2:43 AM
Nice share
Rajeev PunhaniPosted Aug 12, 2016, 12:51 AM
Nice.