PLINQ to Sitecore: Compared with Sitecore Query and old fashioned Foreach

On Kim’s request, I’ve written some additional tests:

        private void PerformWorkOldFashioned()
        {
            using (new SectionTimer("Old fashioned using the foreach and if statement", true))
            {
                foreach (Item item in CurrentItem.Children)
                {
                    if (item.Appearance.Sortorder > 10)
                    {
                        Response.Write(item.DisplayName + "<br />");
                    }
                }
            }
        }
        private void PerformWorkSitecoreQuery()
        {
            using (new SectionTimer("Sitecore Query", true))
            {
                Item[] items = CurrentItem.Axes.SelectItems(".//item[@sortorder>10]");
                foreach (Item item in CurrentItem.Children)
                {
                    Response.Write(item.DisplayName + "<br />");
                }
            }
        }

You can see full test result in this Excel sheet. And I know, their are better ways for profiling, but this one was was setup in another 5 minutes. So that’s cool :).

The final result:

  • LINQ: 53,09 ms
  • PLINQ: 33,9 ms
  • Old fashioned: 37,06 ms
  • Sitecore Query:  59,23 ms

As you can see, PLINQ is the winner, but not as far as you might expect. I should do the same test on a larger dataset and using a performance optimized CTP later on. You can also see the impact of the predicate in the Sitecore Query. Damn! Like Kim mentioned before, Sitecore Queries with predicates are slow :(. Sorry, Jakob ;)!

I’ve also been running Code Matrix on the 4 methods(Maintenance index, Cyclomatic Complexity, Class Compling and Lines of Code

  • LINQ: 63 – 8 – 12 – 7
  • PLINQ: 57 – 8 – 11 – 13
  • Old fashioned: 68 – 5 – 8 – 5
  • Sitecore Query:  68 – 4 – 8 – 5

In this case, Sitecore Query might look like to be the winner, but I guess Visual Studio doesn’t include the complexity behind the query. Taking that in mind, the old fashioned way is the winner, but the result are minimal.

The result for PLINQ is generally caused by the delegate, which introduces a lot of additional lines of codes(whatever that may be ;)).

That’s it for today folks. Tomorrow more about using LINQ with Sitecore!

3 thoughts on “PLINQ to Sitecore: Compared with Sitecore Query and old fashioned Foreach”

  1. It would be interesting to try this on a large dataset. It is as if I only run into gigantic Sitecore solutions lately, and they all ask me why everything is so slow with Sitecore – and all I can say is: The problem is typically not Sitecore, but the queries (or an object 40 cm away from the screen… hehe). But I have noticed that Sitecore typically botches after about 10000 items in one query – even with efficient queries (most databases I work with have between 100.000 and 300.000 – where sometime I am force to search across a major part of the data). I am not saying that plinq will help with these cases, but I am hoping a Quad cpu will allow for at least some splitting of the queries and maybe larger caches in the CPUs…

    I would be interesting to run some test on large dataset – I’ll try that and maybe start my own blog to display the results (when I get the time).

    Thanks for your efforts Alex 🙂

Comments are closed.