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

  • SEARCH
  • Home
  • 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 8647945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:11:52+00:00 2026-06-12T13:11:52+00:00

What is the quickest (and least resource intensive) to compare two massive (>50.000 items)

  • 0

What is the quickest (and least resource intensive) to compare two massive (>50.000 items) and as a result have two lists like the ones below:

  1. items that show up in the first list but not in the second
  2. items that show up in the second list but not in the first

Currently I’m working with the List or IReadOnlyCollection and solve this issue in a linq query:

var list1 = list.Where(i => !list2.Contains(i)).ToList();
var list2 = list2.Where(i => !list.Contains(i)).ToList();

But this doesn’t perform as good as i would like.
Any idea of making this quicker and less resource intensive as i need to process a lot of lists?

  • 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-06-12T13:11:54+00:00Added an answer on June 12, 2026 at 1:11 pm

    Use Except:

    var firstNotSecond = list1.Except(list2).ToList();
    var secondNotFirst = list2.Except(list1).ToList();
    

    I suspect there are approaches which would actually be marginally faster than this, but even this will be vastly faster than your O(N * M) approach.

    If you want to combine these, you could create a method with the above and then a return statement:

    return !firstNotSecond.Any() && !secondNotFirst.Any();
    

    One point to note is that there is a difference in results between the original code in the question and the solution here: any duplicate elements which are only in one list will only be reported once with my code, whereas they’d be reported as many times as they occur in the original code.

    For example, with lists of [1, 2, 2, 2, 3] and [1], the “elements in list1 but not list2” result in the original code would be [2, 2, 2, 3]. With my code it would just be [2, 3]. In many cases that won’t be an issue, but it’s worth being aware of.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a huge log file ( around 1,000,000 lines ). I would like
I am looking for the quickest and easiest way to combine two silverlight projects.
What is the quickest (as in least effort, not super performance) way to convert
I have a List I would like to re-order it so so they are
Given ranges like 0..5.....20....25..40...50......100, I have to determine which range a number is in.
Abstract problem : I have a graph of about 250,000 nodes and the average
What's the quickest way to print debug messages from Flex? You know, things like
Hey all, I seem to have these types of methods everywhere. The method below
What's the quickest way to sort items by number of occurrences on a Linux
Whats the quickest way to unmark all the marked items in VC++ 6.0 Ver?

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.