VB.NET 10 : PLINQ

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!!!