I was reading a blog post on msdn about iterators which talks about about how Concat has O(m^2) performance where m is the length of the first IEnumerable. One of the comments, by richard_deeming on the second page, provides some sample code which he says is much faster. I don’t really understand why it’s faster and was hoping someone could explain it to me.
Thanks.
He’s simply saying that instead of using
Concatto create an iterator which is actually equivalent to creating an iterator over:which is caused by:
create a list of iterators you need and return each of those iterators you created previously.
This way you’re not ending up with a lot of stacked iterators in the first collection of elements.
Also it’s worth mentioning that the claim about
O(m^2)is not “really right”. It’s true in this specific case, but this is like saying+isO(m^2)when you’re calculating(((a+b)+c)+d)...case. It’s the specific usage pattern that makes itO(m^2).