title: Why is the open type Predicate<T> slower than its counterpart
body: <p>Why is a Id == 999999 faster than a lambda expression driven comparison using a Predicate?</p>
  
  <p>Maybe my test itself is not 100% the same, but this is just a sample to show something about a general question: Is a predicate slower than a common Id == 999999 ?</p>
  
  <p>The predicate takes 150 ms while the common compare has 125 ms. From where comes the </p>
  
  <p>difference/overhead? You might ask why I care for 25 ms. Well... I use a open type predicate also in a hierarchical find method and there the gap is much larger.</p>
  
  <p>So I guess the lambda (creating for each "u" a delegate) + predicate is the problem? If not what is wrong with my setup?</p>
  
  <pre><code>   public class UtilitiesTest
          {
              [Test]
              public void Go()
              {
                  var units = GetUnits();
                  DateTime d = DateTime.Now;         
                  var item = units.testme&lt;MyUnit&gt;(u =&gt; u.Id == 999999);
  
                  TimeSpan t = DateTime.Now - d;
  
                  Debug.WriteLine(t.TotalMilliseconds + " ms");
  
  
                  var units1 = GetUnits();
                  DateTime d1 = DateTime.Now;  
  
                  MyUnit item1 = null;
                  foreach (MyUnit unit in units1)
                  {
                      if (unit.Id == 999999)
                      {
                          item1 = unit;
                          break;
                      }
                  }
                  TimeSpan t1 = DateTime.Now - d1;
                  Debug.WriteLine(t1.TotalMilliseconds + " ms");
              }
  
              private IEnumerable&lt;MyUnit&gt; GetUnits()
              {
                  for (int i = 0; i &lt; 1000000; i++)          
                      yield return new MyUnit() { Id = i };            
              }        
          }
  
          class MyUnit
          {
              public int Id { get; set; }
          }
  
      public static T testme&lt;T&gt;(this IEnumerable&lt;T&gt; source, Predicate&lt;T&gt; condition) where T : class
              {
                  foreach (T item in source)
                  {
                      if (condition(item))
                      {
                          return item;
                      }
                  }
                  return default(T);
              }
  </code></pre>