== Resources

=== Documentation

* https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.exists[List<T>.Exists(Predicate<T>)]
* https://learn.microsoft.com/en-us/dotnet/api/system.array.exists[Array.Exists<T>(T[\], Predicate<T>)]
* https://learn.microsoft.com/en-us/dotnet/api/system.collections.immutable.immutablelist-1.exists[ImmutableList<T>.Exists(Predicate<T>)]
* https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.any[Enumerable.Any(Predicate<T>)]
* https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/ef/language-reference/linq-to-entities[LINQ to Entities]

=== Benchmarks

[options="header"]
|===
| Method | Runtime | Mean | StdDev | Ratio | Allocated
| Any | .NET 7.0 | 6.670 ms | 0.1413 ms | 1.00 | 40004 B
| Exists | .NET 7.0 | 1.364 ms | 0.0270 ms | 0.20 | 1 B
| Any | .NET Framework 4.6.2 | 5.380 ms | 0.0327 ms | 1.00 | 40128 B
| Exists | .NET Framework 4.6.2 | 1.575 ms | 0.0348 ms | 0.29 | -
|===

The results were generated by running the following snippet with https://github.com/dotnet/BenchmarkDotNet[BenchmarkDotNet]:

[source,csharp]
----
private List<int> data;
private readonly Random random = new Random();

[Params(1_000)]
public int N { get; set; }

[GlobalSetup]
public void Setup() =>
    data = Enumerable.Range(0, N).Select(x => 43).ToList();

[Benchmark(Baseline = true)]
public void Any()
{
    for (var i = 0; i < N; i++)
    {
        _ = data.Any(x => x % 2 == 0);          // Enumerable.Any
    }
}

[Benchmark]
public void Exists()
{
    for (var i = 0; i < N; i++)
    {
        _ = data.Exists(x => x % 2 == 0);       // List<T>.Exists
    }
}

----

Hardware configuration:

[source]
----
BenchmarkDotNet=v0.13.5, OS=Windows 10 (10.0.19045.2846/22H2/2022Update)
11th Gen Intel Core i7-11850H 2.50GHz, 1 CPU, 16 logical and 8 physical cores
.NET SDK=7.0.203
  [Host]               : .NET 7.0.5 (7.0.523.17405), X64 RyuJIT AVX2
  .NET 7.0             : .NET 7.0.5 (7.0.523.17405), X64 RyuJIT AVX2
  .NET Framework 4.6.2 : .NET Framework 4.8.1 (4.8.9139.0), X64 RyuJIT VectorSize=256
----
