VB.NET 10 : PLINQ

VB.NET 10 : PLINQ

  • Comments 2

LINQ can be more faster with the availability of multi-core desktops. This can be implemented with minimal impact at the code level with existing code.

Here how it looks like,

Dim arrInt = Enumerable.Range(1, 4000000)

Dim q =

    From n In arrant

    Where (IsPrime(n))

    Select n

In my dual core machine it takes around 2693 millisecond. But with a little tweak you can make it faster

Dim q =

    From n In arrInt.AsParallel()

    Where (IsPrime(n))

    Select n

Now this takes 1527 milliseconds. Clearly something to think about.

Behind the scene

What happens in this case? All the Where / Select becomes Lambda expression like

arrInt.AsParallel().Where(Function(n) IsPrime(n)).Select(Function(n) n)

 

When we were using without AsParallel(), Where/Select were coming from Enumerable class. After we have implemented the AsParallel() it now calls the method from ParallelEnumerable class.

 

ParallelEnumerable class internally implements the new “Task” API.

 

Namoskar!!!

Leave a Comment
  • Please add 7 and 7 and type the answer here:
  • Post
  • .NET should detect multi-core functionality at runtime and invoke .AsParallel() automatically.

    If someone doesn't want all the processing power, they can could a command to turn PLINQ off.

  • thanks

Page 1 of 1 (2 items)