SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Does anyone know how the performance of searching for items compares to using the object model to access them?

When I say "object model" i mean using SPList to get a collection of SPListItems and iterating through. Example:

foreach (SPListItem li in w.Lists[ListName].Items.Cast<SPListItem>().Where(t => Convert.ToDateTime(t["pubenddate"]) >= DateTime.Now))

If I were using search to do this, I would define a search scope that only includes items where pubenddate >= Today's Date, select all items and do my foreach on that.

So i'm wondering:

  1. Does the number of items in the target list affect which of these will perform faster?
  2. Is one of these methods always faster than the other?
  3. Is one of these generally considered "best practice"?
  4. Is one of these methods better if I am looking through multiple lists?
share|improve this question
up vote 6 down vote accepted

there are several good ways of retreiving data. Each has its pros and cons.

Typically Search would be used when you want to list some, but not all, data (not all can be exposed) and when you want to retrieve data across site collectons.

SPQuery, SPSiteDataQuery and PortalSitemapProvider are good candidates if you are on the same site collection.

See some performance metrics here

share|improve this answer
Awesome link, thanks! – Abe Miessler Sep 1 '11 at 19:49

Best practice is to use SPQuery on the list to return list items that match your criteria.

See the software performance boundaries documentation here has some details (pertaining to 2007):

2010 info is here:

There was another document that addressed this as well from Microsoft that compared the performance of the different lookup methods. I'll see if I can dig it up, but the gist of it is that you should NOT iterate the list to find items.

So in summary:

  1. Yes. Don't loop through the list
  2. Yes. For any non-trivial case, SPQuery and SPSiteDataQuery will always be faster.
  3. Yes. Use SPQuery or SPSiteDataQuery
  4. Yes. Use SPSiteDataQuery

If you have well defined content types, you can also consider using LINQ-to-SharePoint, but it's good to have a background and understanding of CAML queries in general so I advise familiarization with both SPQuery and SPSiteDataQuery.

Found it: 2007 whitepaper: this document has a good reference for the differences in list query performance.

And the 2010 info:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.