Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 406461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:29:55+00:00 2026-05-12T17:29:55+00:00

I just want know if a FindAll will be faster than a Where extentionMethod

  • 0

I just want know if a “FindAll” will be faster than a “Where” extentionMethod and why?

Example :

myList.FindAll(item=> item.category == 5);

or

myList.Where(item=> item.category == 5);

Which is better ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T17:29:55+00:00Added an answer on May 12, 2026 at 5:29 pm

    Well, FindAll copies the matching elements to a new list, whereas Where just returns a lazily evaluated sequence – no copying is required.

    I’d therefore expect Where to be slightly faster than FindAll even when the resulting sequence is fully evaluated – and of course the lazy evaluation strategy of Where means that if you only look at (say) the first match, it won’t need to check the remainder of the list. (As Matthew points out, there’s work in maintaining the state machine for Where. However, this will only have a fixed memory cost – whereas constructing a new list may require multiple array allocations etc.)

    Basically, FindAll(predicate) is closer to Where(predicate).ToList() than to just Where(predicate).

    Just to react a bit more to Matthew’s answer, I don’t think he’s tested it quite thoroughly enough. His predicate happens to pick half the items. Here’s a short but complete program which tests the same list but with three different predicates – one picks no items, one picks all the items, and one picks half of them. In each case I run the test fifty times to get longer timing.

    I’m using Count() to make sure that the Where result is fully evaluated. The results show that collecting around half the results, the two are neck and neck. Collecting no results, FindAll wins. Collecting all the results, Where wins. I find this intriguing: all of the solutions become slower as more and more matches are found: FindAll has more copying to do, and Where has to return the matched values instead of just looping within the MoveNext() implementation. However, FindAll gets slower faster than Where does, so loses its early lead. Very interesting.

    Results:

    FindAll: All: 11994
    Where: All: 8176
    FindAll: Half: 6887
    Where: Half: 6844
    FindAll: None: 3253
    Where: None: 4891
    

    (Compiled with /o+ /debug- and run from the command line, .NET 3.5.)

    Code:

    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    
    class Test
    {
        static List<int> ints = Enumerable.Range(0, 10000000).ToList();
    
        static void Main(string[] args)
        {
            Benchmark("All", i => i >= 0); // Match all
            Benchmark("Half", i => i % 2 == 0); // Match half
            Benchmark("None", i => i < 0); // Match none
        }
    
        static void Benchmark(string name, Predicate<int> predicate)
        {
            // We could just use new Func<int, bool>(predicate) but that
            // would create one delegate wrapping another.
            Func<int, bool> func = (Func<int, bool>) 
                Delegate.CreateDelegate(typeof(Func<int, bool>), predicate.Target,
                                        predicate.Method);
            Benchmark("FindAll: " + name, () => ints.FindAll(predicate));
            Benchmark("Where: " + name, () => ints.Where(func).Count());
        }
    
        static void Benchmark(string name, Action action)
        {
            GC.Collect();
            Stopwatch sw = Stopwatch.StartNew();
            for (int i = 0; i < 50; i++)
            {
                action();
            }
            sw.Stop();
            Console.WriteLine("{0}: {1}", name, sw.ElapsedMilliseconds);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.