title: What happened to Array.Sort() in .NET 4.0? Is TrySZSort() gone?
body: <p>I wonder why the following snippet does not give the expected result? It sorts a not too small random array and uses 3 different methods for it. I was expecting the speed to come out as so: </p>
  
  <ol>
  <li>Array.Sort() - fastest by using the native TrySZSort function as I recall from .NET 2.0</li>
  <li>Descending sort by using the custom Comparer class</li>
  <li>The lambda expression sort.   </li>
  </ol>
  
  <p>The Code: </p>
  
  <pre><code>class DescComparer : IComparer&lt;double&gt; {
      // simple comparison 
      // (yes, its not exactly correct ...)
      public int Compare(double x, double y) {
          return (x &gt; y) ? -1 : 1; 
      }
  }
  static void Main(string[] args) {
      Stopwatch sw = new Stopwatch(); 
      Random rand = new Random(); 
      DescComparer comparer = new DescComparer();
      double[] a = new double[1000000]; 
      for (int r = 0; r &lt; 20; r++) {
  
          // init array
          for (int i = 0; i &lt; a.Length; i++) a[i] = rand.NextDouble();  
          sw.Restart();
          Array.Sort(a);
          sw.Stop();
          Console.WriteLine("ascending took: {0} ms ", sw.ElapsedMilliseconds);
  
          // init array
          for (int i = 0; i &lt; a.Length; i++) a[i] = rand.NextDouble();
          sw.Restart();
          Array.Sort&lt;double&gt;(a, comparer);
          sw.Stop();
          Console.WriteLine("descending took: {0} ms ", sw.ElapsedMilliseconds);
  
          // init array
          for (int i = 0; i &lt; a.Length; i++) a[i] = rand.NextDouble();
          sw.Restart();
          Array.Sort&lt;double&gt;(a, (x,y) =&gt; -x.CompareTo(y));
          sw.Stop();
          Console.WriteLine("desc lambda took: {0} ms ", sw.ElapsedMilliseconds);
  
      }
      Console.Read(); 
  }
  </code></pre>
  
  <p>But strangely, it gives the following: </p>
  
  <pre><code>ascending took: 514 ms
  descending took: 537 ms
  desc lambda took: 915 ms
  ascending took: 511 ms
  descending took: 492 ms
  desc lambda took: 923 ms
  ascending took: 511 ms
  descending took: 483 ms
  desc lambda took: 912 ms
  ascending took: 511 ms
  descending took: 485 ms
  desc lambda took: 914 ms
  ascending took: 518 ms
  descending took: 485 ms
  desc lambda took: 924 ms
  ... a.s.o. ...
  </code></pre>
  
  <p>So, the lambda really is slowest. But how comes, the plain ascending Array.Sort is not faster anymore? Is it, because Array.Sort(T[], Comparer) has been improved or has TrySZSort simply been removed? Or did I miss something?  </p>
  
  <p>(Release build, no Debug, no Reflector available right now ;) ) Thanks! </p>
  
  <p>UPDATE: 
  According to the hint by @Reed Copsey, the lambda expression is not fair. I tried to change it to the same as the comparer does. The speed went up. Asc / lambda went from 55% -> 75%. So it still is considerably slower.</p>