Alois Kraus


  Home  |   Contact  |   Syndication    |   Login
  118 Posts | 8 Stories | 310 Comments | 162 Trackbacks




This is my first test post with Windows Live Writer 2008. I hope it will not mess up when I paste source code ....

But back to business. VS2008 formerly known as Orcas is out! It is just great and has many cool features inside it.

You can download various editions of Visual Studio 2008 at the following locations.

One of the best features are Language Integrated Queries (LINQ). The first question that does arise is if LINQ to Objects is able to replace common for loops in terms of performance in every case. To check it out I did write a very simple test where we filter for specific items in an array and return the filtered list.

List<string> Test = new List<string> { "This", "is", "a", "list", "that", "will", "be", "filtered", "with",
"a", "for", "loop", "and", "LINQ"};


List<string> FilterFor(string substr)
     List<string> ret = new List<string>();

     foreach (string str in Test)
         if (str.Contains(substr))

     return ret;


List<string> FilterForLinq(string substr)
     var ret = from str in Test where str.Contains(substr) select str;
     return ret.ToList<string>();


On my Intel Core Duo 6600 @ 2.40 GHz with 3 GB RAM I get

  First Call in ms Tight Loop in Calls/ms
FilterFor 1 584
FilterForLinq 2 454
FilterForLinq with IEnumerable<string> as return value 1 17543



The values were measured with the .NET Framework 3.5 RTM in release configuration. It seems that for simple filters we see a small (20%) speed loss if we use LINQ in very tight loops. But when I used a profiler (ANTS 3.0) I did get no speed difference. Since the profiler uses callbacks to get the exact timing we loose data locality and CPU cache benefits which slows the program nearly 100 times down such small effects are not visible anymore.

When we do only create the query but do not execute it we are over 30 times faster than the traditional array based approach. Lazy evaluation is the key to defer the actual work if we do not need all values or do not use them always. Huge speed gains are possible by doing only as much work as need but no more. I am looking forward to PLINQ which could take advantage of my two CPUs.

If you want to get started with more complex queries I recommend the 101 LINQ Samples site to learn what you can do with such queries or MSDN.

posted on Tuesday, November 20, 2007 1:27 PM


# re: Visual Studio VS2008 Is Out! 11/28/2007 11:19 AM Brian Finnerty
Some free LINQ to SQL training (hands-on) is available from InnerWorkings:

Post A Comment