title: Visual Studio C# 2010 Express Debug running Faster than Release
body: <p>I have a Windows Forms application with exactly 2 threads. These threads have ZERO interaction with each other, Ala the first thread runs without messing with the second thread. There is no Synchronization between them, as there is no need for that to be happening. The first thread deals with the UI of the application, changing colors and labels and has One timer running to catch some user input this timer fires every 200 milliseconds. The second Thread is more involved and runs through its coding constantly until shutdown by the user by exiting the application. </p>
  
  <p>The Second Thread first reads from memory and stores the data into a List, then uses this data to make some calculations. I have a StopWatch class timer to measure the time it takes to complete one iteration of the Second Thread. This timer is reset and started at the very beginning of the thread and then stopped and printed to console once the thread has completed an iteration. This is where I have been getting my performance data. I have been allowing the Thread to run for at least 1000 iterations and then doing an average excluding the first run. </p>
  
  <p>The DEBUG version of the build, that is the build that is run by the VSHOST or when one would hit F5 in Visual Studio C# 2010 Express. The Timings average in at 0.00035s that is 0.35ms. </p>
  
  <p>When the application is run outside of the VSHOST, either by hitting Ctrl-F5 or by running the application from the .exe that is produced when hitting BUILD. I have also used REBUILD to test this with absolutely ZERO change. The timings average in at .365s that is 365ms. That is roughly 1000x slower with the Release Build. </p>
  
  <p>I am at a complete loss as to what is going on. What is the VSHOST doing that is allowing the program to run so quickly. I have made sure that all Variable initialization is accounted for and correct. That being said I have no clue why something like this would be happening. Any insight as to why I am getting such a performance Dip?</p>
  
  <p>As a side note the computer I am using is 64bit has a quad core i7 with Hyper Threading, 16 Gigabytes of ram and twin HD6750's. So it does not seem to be an issue of having too many threads, the only thing here that may be an issue is the Hyper Threading.</p>
  
  <p>A snippet of code in the form of what my application does. However it is not possible to give working code as the memory address read is where the slow down occurs. </p>
  
  <pre><code>namespace Test Snippet
  {
  public struct Data
  {
      public float X;
      public float Y;
      public float Z;
      public float dX;
      public float dY;
  
      public Data(int c)
      {
          this.X = ReadFloat(Base + 0x50 + (c * 0x10));
          this.Y = ReadFloat(Base + 0x50 + (c * 0x10));
          this.Z = ReadFloat(Base + 0x50 + (c * 0x10));
          if (this.Z == 1)
          {
              targetindex = c;
          }
          this.dX = 0;
          this.dY = 0;
      }
  }
  class Class1
  {
      public int Base = new int();
      public List&lt;Data&gt; data = new List&lt;Data&gt;();
      public int targetindex = new int();
      public Data targetdata = new Data();
  
      public void GetData()
      {
          while (true)
          {
              data.Clear();
              for (int c = 0; c &lt; 64; c++)
              {
                  Data tempdata = new Data();
                  teampdata = new Data(c);
                  data.Add(tempdata);
              }
              if (data.Count != 0)
              {
                  targetdata = data[targetindex];
                  data.RemoveAt(targetindex);
                  targetdata.dX = ReadFloat(Base + 0x66);
                  targetdata.dY = ReadFloat(Base + 0x65);
                  Data[] tempdatarray = new Data[data.Count];
                  for (int j = 0; j &lt; tempdatarray.Length; j++)
                  {
                      tempdatarray[j].dX = (float)Math.Acos(targetdata.dX * 10);
                      tempdatarray[j].dY = (float)Math.Acos(targetdata.dY * 10);
                  }
              }
  
          }
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>EDIT:: I have tried the same procedure but without using threading. I had the thread function called by the Timer I was using to catch User Input. I am getting the same results. So that means that threading does not seem to be the issue. I have also done the test on a different computer and for some reason I am not getting the massive difference. Which leads me to believe there may be something wrong with my computer, or something dealing with how my processor deals with threads due to its Hyper Threading ability. Anyone know if Hyper Threading causes issues with a multi-threaded application that is not utilizing it explicitly from within the program. Which honestly I would not have a clue how to set up.</p>