Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>According to documentation:</strong></p> <p>List.Exists (Object method)</p> <blockquote> <p>Determines whether the List(T) contains elements that match the conditions defined by the specified predicate.</p> </blockquote> <p>IEnumerable.Any (Extension method)</p> <blockquote> <p>Determines whether any element of a sequence satisfies a condition.</p> </blockquote> <p>List.Contains (Object Method)</p> <blockquote> <p>Determines whether an element is in the List.</p> </blockquote> <p><strong>Benchmarking:</strong></p> <p><strong><em>CODE:</em></strong></p> <pre><code> static void Main(string[] args) { ContainsExistsAnyShort(); ContainsExistsAny(); } private static void ContainsExistsAny() { Console.WriteLine("***************************************"); Console.WriteLine("********* ContainsExistsAny ***********"); Console.WriteLine("***************************************"); List&lt;int&gt; list = new List&lt;int&gt;(6000000); Random random = new Random(); for (int i = 0; i &lt; 6000000; i++) { list.Add(random.Next(6000000)); } int[] arr = list.ToArray(); find(list, arr); } private static void ContainsExistsAnyShort() { Console.WriteLine("***************************************"); Console.WriteLine("***** ContainsExistsAnyShortRange *****"); Console.WriteLine("***************************************"); List&lt;int&gt; list = new List&lt;int&gt;(2000); Random random = new Random(); for (int i = 0; i &lt; 2000; i++) { list.Add(random.Next(6000000)); } int[] arr = list.ToArray(); find(list, arr); } private static void find(List&lt;int&gt; list, int[] arr) { Random random = new Random(); int[] find = new int[10000]; for (int i = 0; i &lt; 10000; i++) { find[i] = random.Next(6000000); } Stopwatch watch = Stopwatch.StartNew(); for (int rpt = 0; rpt &lt; 10000; rpt++) { list.Contains(find[rpt]); } watch.Stop(); Console.WriteLine("List/Contains: {0:N0}ms", watch.ElapsedMilliseconds); watch = Stopwatch.StartNew(); for (int rpt = 0; rpt &lt; 10000; rpt++) { list.Exists(a =&gt; a == find[rpt]); } watch.Stop(); Console.WriteLine("List/Exists: {0:N0}ms", watch.ElapsedMilliseconds); watch = Stopwatch.StartNew(); for (int rpt = 0; rpt &lt; 10000; rpt++) { list.Any(a =&gt; a == find[rpt]); } watch.Stop(); Console.WriteLine("List/Any: {0:N0}ms", watch.ElapsedMilliseconds); watch = Stopwatch.StartNew(); for (int rpt = 0; rpt &lt; 10000; rpt++) { arr.Contains(find[rpt]); } watch.Stop(); Console.WriteLine("Array/Contains: {0:N0}ms", watch.ElapsedMilliseconds); Console.WriteLine("Arrays do not have Exists"); watch = Stopwatch.StartNew(); for (int rpt = 0; rpt &lt; 10000; rpt++) { arr.Any(a =&gt; a == find[rpt]); } watch.Stop(); Console.WriteLine("Array/Any: {0:N0}ms", watch.ElapsedMilliseconds); } </code></pre> <p><strong>RESULTS</strong></p> <pre class="lang-none prettyprint-override"><code>*************************************** ***** ContainsExistsAnyShortRange ***** *************************************** List/Contains: 96ms List/Exists: 146ms List/Any: 381ms Array/Contains: 34ms Arrays do not have Exists Array/Any: 410ms *************************************** ********* ContainsExistsAny *********** *************************************** List/Contains: 257,996ms List/Exists: 379,951ms List/Any: 884,853ms Array/Contains: 72,486ms Arrays do not have Exists Array/Any: 1,013,303ms </code></pre>
 

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