title: C#: ToArray performance
body: <h2>Background:</h2>
  
  <p>I admit I did not attempt to benchmark this, but I'm curious...</p>
  
  <p>What are the CPU/memory characteristics of the <code>Enumerable.ToArray&lt;T&gt;</code> (and its cousin <code>Enumerable.ToList&lt;T&gt;</code>)?</p>
  
  <p>Since <code>IEnumerable</code> does not advertise in advance how many elements it has, I (perhaps naively) presume <code>ToArray</code> would have to "guess" an initial array size, and then to resize/reallocate the array if the first guess appears to be too small, then to resize it yet again if the second guess appears to be too small etc... Which would give worse-than-linear performance.</p>
  
  <p><em>I can imagine better approaches involving (hybrid) lists, but this would still require more than one allocation (though not reallocation) and quite bit of copying, though it could be linear overall despite the overhead.</em></p>
  
  <h2>Question:</h2>
  
  <p>Is there any "magic" taking place behind the scenes, that avoids the need for this repetitive resizing, and makes <code>ToArray</code> linear in space and time?</p>
  
  <p>More generally, is there an "official" documentation on BCL performance characteristics?</p>