== Resources === Documentation * https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.exists[List.Exists(Predicate)] * https://learn.microsoft.com/en-us/dotnet/api/system.array.exists[Array.Exists(T[\], Predicate)] * https://learn.microsoft.com/en-us/dotnet/api/system.collections.immutable.immutablelist-1.exists[ImmutableList.Exists(Predicate)] * https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.any[Enumerable.Any(Predicate)] * 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 | Standard Deviation | Allocated | Any | .NET 7.0 | 6.670 ms | 0.1413 ms | 40004 B | Exists | .NET 7.0 | 1.364 ms | 0.0270 ms | 1 B | Any | .NET Framework 4.6.2 | 5.380 ms | 0.0327 ms | 40128 B | Exists | .NET Framework 4.6.2 | 1.575 ms | 0.0348 ms | - |=== ==== Glossary * https://en.wikipedia.org/wiki/Arithmetic_mean[Mean] * https://en.wikipedia.org/wiki/Standard_deviation[Standard Deviation] * https://en.wikipedia.org/wiki/Memory_management[Allocated] The results were generated by running the following snippet with https://github.com/dotnet/BenchmarkDotNet[BenchmarkDotNet]: [source,csharp] ---- private List 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.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 ----