Geeklog
There's no place like 127.0.0.1 - ramblings about programming

Another LINQ Test

September 7, 2009 18:23 by The Geek

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):

  1. foreach (~150ms)
  2. Predicate (~144ms)
  3. LINQ on a generic list (~209ms)
  4. 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)


Comments

September 10. 2009 20:25

ttest

test

ttest