title: c# Performance slowdown while looping/iterating through a long process
body: <p><strong>OVERVIEW</strong><br>
  I am facing performance slowdown while iterating MANY times through a calculator class.
  Iterations take about 3mn each at the beginning and take longer and longer as the iteration count grows (30mn+/per process). I have to Stop the program/Restart the execution where I left it to come back to normal conditions (3mn/per process).</p>
  
  <p><strong>WHAT I DO</strong><br>
  I have a scientific application that tests a set of parameters over a process. 
  For example I have N scenarios (i.e a parameter combination), tested over an experimentation set, that consists in a calculator class that takes the parameters in input, processes them against T possible XP conditions, and stores the output in ORM objects, that are fired to DB after each iteration.<br> In other words, Each of the N Parameters combination is passed T times trough the calculator.</p>
  
  <pre><code>Parameter combination : Params Set 1, Params Set 2, ...., Params Set  N
  Experimental Set      : XP Set 1    , XP Set 2    , ...., XP Set T
  </code></pre>
  
  <p>So I have NxT combinations,  N and T being around 256 each, which give 65000+ iterations.</p>
  
  <p><strong>HOW I DO IT</strong><br>
  I have a GUI to fix the parameter sets, and launch Background Workers (one per Parameter combination). Each Backrgound worker loads the first of the T XP sets, executes the current Parameter Set, move to next XP Set, and so on .  A report is generated after each single iteration by the calculator (i.e after each Nx/Tx) and an event is fired to populate .NET Linq/SQL ORM objects (AgileFX) and store them into an SQL Server Database.</p>
  
  <p><strong>THE PROBLEM</strong><br>
  The process runs fine the first 30mn and then slowly begins to drift, each iteration taking longer and longer (Sound like a memory overflow or so...)</p>
  
  <p><strong>HINT</strong><br>
  Oddly enough, an experimenter noticed very pertinently that <strong><em>the processing time grows in a linear fashion</em></strong> : +3mn more of the precedent processing time. Which comes down to an arithmetic progression (Tn+1 = Tn + 3mn)
  I have a 12-Core INTEL and 24GB RAM</p>