I am trying to understand PLINQ. So for that,I am querying database which has 102915 products in it.
But shockingly I am seeing that PLINQ takes 18 secs where normal query takes only 4 secs. To understand, I have read this article, PLINQ Performs Worse Than Usual LINQ. But still, I couldn't understand why this took so many secs.
To remove over head, I removed .order(m.sku)
in PLINQ, but still it gives same result. Here, is a code for LINQ and PLINQ version.
PLINQ Version
shootersEntities model = new shootersEntities();
var IsOnline = cBOnline.Checked;
var IsDeleted = cBDeleted.Checked;
Stopwatch s = new Stopwatch();
s.Start();
var p = from m in model.products.AsParallel()
where ((m.productOnline == IsOnline) || (m.deleted == IsDeleted))
select new { m.sku, m.productCode, m.quantity };
var list = p.ToList();
s.Stop();
MessageBox.Show((s.ElapsedMilliseconds / 1000).ToString());
dataGridView1.DataSource = list;
LINQ Version
shootersEntities model = new shootersEntities();
var IsOnline = cBOnline.Checked;
var IsDeleted = cBDeleted.Checked;
Stopwatch s = new Stopwatch();
s.Start();
var p = from m in model.products
where ((m.productOnline == IsOnline) || (m.deleted == IsDeleted))
select new { m.sku, m.productCode, m.quantity };
var list = p.ToList();
s.Stop();
MessageBox.Show((s.ElapsedMilliseconds / 1000).ToString());
dataGridView1.DataSource = list;