IntroductionPLINQ automatically parallelizes local LINQ queries. PLINQ has the advantage ofbeing easy to use in that it offloads the burden of both work partitioning and resultcollation to the Framework. How to partitioning workingWihtout PLIINQWith PLINQpublic static void callPlinQ()
{
DateTime daa = new DateTime();
daa = DateTime.Now;
IEnumerable<int> numbersx = Enumerable.Range(3, 1000000 - 3);
var parallelQueryx = from n in numbersx.AsParallel()
where Enumerable.Range(2, (int)Math.Sqrt(n)).All(i => n % i > 0)
select n;int[] primesx = parallelQueryx.ToArray();
DateTime exx = new DateTime();
exx = DateTime.Now;
Console.WriteLine(" in PLINQ "+(exx - daa).ToString());
}With LINQpublic static void callLinQ()
{
DateTime da = new DateTime();
da = DateTime.Now;
IEnumerable<int> numbers = Enumerable.Range(3, 1000000 - 3);
var parallelQuery = from n in numbers
where Enumerable.Range(2, (int)Math.Sqrt(n)).All(i => n % i > 0)
select n;int[] primes = parallelQuery.ToArray();
DateTime ex = new DateTime();
ex = DateTime.Now;
Console.WriteLine("LINQ "+(ex - da).ToString());
}Enjoy the PLINQ. Sample Project SourceDownload source files -23 kb |