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?

2 Answers 2


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


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): http://technet.microsoft.com/en-us/library/cc287790%28office.12%29.aspx

2010 info is here: http://technet.microsoft.com/en-us/library/cc262787.aspx

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: http://technet.microsoft.com/en-us/library/cc262813(office.12).aspx this document has a good reference for the differences in list query performance.

And the 2010 info: http://technet.microsoft.com/en-us/library/cc262813.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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