I got a basic question when I tried with Plinq (Parallel linq ) to object collection and I observed that Plinq Vs normal operation does not have much difference in terms of execution time. Could anybody can check my code and advice me why so happening. I have run this code in i7 processor.
class Program
{
static void Main(string[] args)
{
new Program().Plinq();
new Program().linq();
Console.ReadLine();
}
void Plinq()
{
DateTime startTime = DateTime.Now;
var query1 = (from port in new XpressEntities().Portfolios.Take(1000000)
select new port { PortId = port.PORT_ID, CFAC = port.CFAC }).ToList<port>();
query1.AsParallel().Where(e => e.PortId == 0);
TimeSpan ts = DateTime.Now.Subtract(startTime);
Console.WriteLine("Time Elapsed: {0} Seconds:MilliSeconds in Paralel mode", ts.Seconds + ":" + ts.Milliseconds);
}
void linq()
{
DateTime startTime = DateTime.Now;
var query1 = (from port in new XpressEntities().Portfolios.Take(1000000)
select new port { PortId = port.PORT_ID, CFAC = port.CFAC }).ToList<port>();
query1.Where(e => e.PortId == 0);
TimeSpan ts = DateTime.Now.Subtract(startTime);
Console.WriteLine("Time Elapsed: {0} Seconds:MilliSeconds in Normal mode", ts.Seconds + ":" + ts.Milliseconds);
}
}
class port
{
public int PortId { get; set; }
public string CFAC { get; set; }
}
Result of above code is
Time Elapsed: 6:411 Seconds:MilliSeconds in Paralel mode
Time Elapsed: 6:68 Seconds:MilliSeconds in Normal mode