c# - Why PLINQ is giving worse performance then LINQ Query? -
i trying understand plinq. that,i querying database has 102915 products in it.
but shockingly seeing plinq takes 18 secs normal query takes 4 secs. understand, have read article, plinq performs worse usual linq. still, couldn't understand why took many secs.
to remove on head, removed .order(m.sku)
in plinq, still gives same result. here, code linq , plinq version.
plinq version
shootersentities model = new shootersentities(); var isonline = cbonline.checked; var isdeleted = cbdeleted.checked; stopwatch s = new stopwatch(); s.start(); var p = m in model.products.asparallel() ((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 = m in model.products ((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;
probably because linq version translates query sql (which may or may not run in parallell on server) while plinq version needs retrieve database , run filtering , sorting itself.
Comments
Post a Comment