I just had an interesting exchange about using .Except versus .Any, and the performance difference between them.
I’m wondering if there is a resource online that explains the different implementations of LINQ to objects, and what the performance implications are.
I checked MSDN and hookedonlinq.com, and neither mentions that .Except builds a HashSet, whereas using array.Any(item => otherarray.Contains(item)) will simply iterate the second array for each item – performance of O(n²) for .Any vs O(n) for .Except
Absolutely – my Edulinq series 🙂
More precisely, that’s a blog series about how LINQ to Objects can be implemented, with various discussions around performance etc. I’m not going to guarantee that the “real” implementation always takes the same route… but I wouldn’t expect them to differ wildly.
As well as each operator being covered individually, the latest posts are more general, talking about performance trade-offs etc.