Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First off, I think your logic is just plain wrong. Passing a delegate to Contains to the Any method will do partial string matches and you have explicitly stated that you want only exact matches.</p> <p>Leaving that aside, your performance problem is due to the nature of the list data structure; it was not designed to be efficiently searched via "Any".</p> <p>The problem is that "Any" simply does a linear search, starting at the beginning of the list and blazing through it until it finds a match. If the list has 100K entries then every "miss" will do 100K string comparisons, and every "hit" will do on average 50K string comparisons.</p> <p>That's terrible.</p> <p>What you should do is convert the List into a HashSet of strings. The set takes up slightly more memory, but is <em>extremely</em> fast to search.</p> <p>Another possible optimization is to sort one of the lists -- which is an O(n lg n) operation -- and then binary search the sorted list, which is an O(lg n) operation. </p> <p>A third possible optimization is to sort both lists, and then write a sorted list comparer. Obviously a sorted list comparer is much faster than an unsorted list comparer. You keep an index into each list, and advance only the index that is pointing to the "smaller" item. That is, if the lists are</p> <pre><code>A, B, C, D, G, I B, D, E, H, I </code></pre> <p>Then you start with indexes pointing at A and B. "A" is smaller, so you advance the first index to "B". Now they are the same; you have a match. Advance both of them. The first index is "C" and the second is "D". "C" is smaller", so advance it...</p> <hr> <p>More generally though, I think you are describing the problem at too low a level. I feel like you're asking a question about drills when you should be asking a question about holes. Maybe a drill isn't the right tool in the first place. Can you tell us <em>why</em> you are matching two big lists of strings? Perhaps there is an easier way to do what you want. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload