Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should be able to cut the time approximately in half by exiting the inner loop after finding a matching part number. That is, put a <code>break</code> as the last statement in the code that's executed when the part numbers match.</p> <p>Still, half of forever is still forever.</p> <p>With just 40,000 rows, you could easily populate a dictionary that contains the contract number and part number as the key, and the conversion table row index as the value. Something like:</p> <pre><code>Dictionary&lt;string, int&gt; conversionLookup = new Dictionary&lt;string, int&gt;(); for (int i = 0; i &lt; dtConversion.Rows.Count; ++j) { conversionLookup.Add(string.Format("{0}:{1}", dtConversion.Rows[j]["vend_contract_no"].ToString(), dtConversion.Rows[j]["vend_item_id"].ToString()), j); } </code></pre> <p>Then, your outer loop becomes:</p> <pre><code>for (int i = 0; i &lt; dtFromTableContracts.Rows.Count; i++) { partNumber2 = dtFromTableContracts.Rows[i]["supplier_part_no"].ToString(); contract_no2 = dtFromTableContracts.Rows[i]["contract_no"].ToString(); string lookup = string.Format("{0}:{1}", contract_no2, partNumber2); int ix; if (conversionLookup(lookup, out ix)) { // update dtConversion.Rows[ix] } } </code></pre> <p>I'm not familiar with the restrictions on your part numbers (you use <code>StartsWith</code> rather than equals in your inner loop), so you might have to adjust the indexes somewhat.</p> <p>That should be very fast.</p> <p>If you can't create keys that use the contract number for a direct lookup, you could do something quite similar by creating a <code>List</code> with the contract numbers and part numbers, and binary search it. That would be O(m log n) rather than O(m * n). Still quite a bit faster.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload