c# - Is there a faster way for filtering in datatable? -
c# - Is there a faster way for filtering in datatable? -
i have datatable contains 2.5m rows. filter rows in datatable.
columns of datatable :
[intcode] long [bdintcode] long [txndt] datetime [txnquantity] decimal [recorduser] long [recorddt] datetime
my code below :
foreach (var downwards in breakdowns) { sw.start(); var relatedbreakdowns = firstgroup.where(x => x.relatedbdintcode == down.processingrowintcode).tolist(); if (relatedbreakdowns.count == 0) continue; var filters = string.format("bdintcode in ({0})", string.join(",", relatedbreakdowns.select(x => x.bdintcode))); var filtereddatatable = datatable.select(filters, "bdintcode"); foreach (var datarow in filtereddatatable) { var r = datatableschema.newrow(); r["recorduser"] = recorduser; r["recorddt"] = datetime.now; r["txnquantity"] = datarow["txnquantity"]; r["txndt"] = datarow["txndt"]; r["bdintcode"] = down.processingrowintcode; datatableschema.rows.add(r); } sw.stop(); count++; console.writeline("group: " + unrelatedbreakdowngroup.relatedbdgroupintcode + ", count : " + count + ", elapsedtime : ms = " + sw.elapsedmilliseconds + ", sec = " + sw.elapsedmilliseconds / 1000f ); sw.reset(); }
the count of breakdowns list 1805, count of firstgroup list 9880.
personally, start having in list<sometype>
, not data-table. index data: in case, searching relatedbdintcode
, expecting multiple matches, so:
var index = firstgroup.tolookup(x => x.relatedbdintcode); foreach (var downwards in breakdowns) { var matches = index[down.processingrowintcode].tolist(); //... }
this avoids doing finish scan of firstgroup
every item in breakdowns
.
the next in
moved indexed search, time presumably on bdintcode
.
c# datatable
Comments
Post a Comment