Yes, this has been discussed quite a bit but I wanted to do a quick test on LINQ code performance. There's a link at the end of this post that contains the very simple code.
I wrote a quick program that would test 4 methods of enumerating a collection (results in brackets):
-
foreach (~150ms)
-
Predicate (~144ms)
-
LINQ on a generic list (~209ms)
-
LINQ on an IQueryProvider (~200ms)
All it does is fill a collection with a bunch of objects and then enumerate the collection to find any items that match the criteria. For this simple test, we just check that the object's WholeNumber property == 10.
Unsurprisingly, LINQ is slower - which is a shame because I quite like the readability of LINQ code. The good thing is that using IQueryProvider is no slower than standard LINQ which means that if you do want to implement a custom LINQ provider - for operations on a file system or a custom DB format - then the overhead is not very high and may well be worth the flexibility that LINQ provides.
LinqTest.zip (408.51 kb)
1ece2bd5-8075-4196-a2c4-c06180e06899|0|.0