title: [Optimize This]: Slow LINQ to Objects Query
body: <p>I have this query that is bothering me; it is encapsulated as a new query operator, I made two versions of it, trying to see which one performs better. Both perform horribly.</p>
  
  <p>First attempt; declarative style</p>
  
  <pre><code>public static IEnumerable&lt;IEnumerable&lt;α&gt;&gt; Section&lt;α&gt;(this IEnumerable&lt;α&gt; source, int length)
  {
      return source.Any()
          ? source.Take(length).Cons(source.Skip(length).Section(length))
          : Enumerable.Empty&lt;IEnumerable&lt;α&gt;&gt;();
  }
  </code></pre>
  
  <p>Second attempt: imperative "yield return" style</p>
  
  <pre><code>public static IEnumerable&lt;IEnumerable&lt;α&gt;&gt; Section&lt;α&gt;(this IEnumerable&lt;α&gt; source, int length)
  {
      var fst = source.Take(length);
      var rst = source.Skip(length);
  
      yield return fst;
  
      if (rst.Any())
          foreach (var section in rst.Section(length))
              yield return section;
  }
  </code></pre>
  
  <p>In fact the second attempt is worse, both in terms of readability, compositionality and in terms of speed.</p>
  
  <p>Any clues as to how to optimize this?</p>