== Resources

=== Documentation

* https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.find[List<T>.Find(Predicate<T>)]
* https://learn.microsoft.com/en-us/dotnet/api/system.array.find[Array.Find<T>(T[\], Predicate<T>)]
* https://learn.microsoft.com/en-us/dotnet/api/system.collections.immutable.immutablelist-1.find[ImmutableList<T>.Find(Predicate<T>)]
* https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.firstordefault[Enumerable.FirstOrDefault(Predicate<T>)]

=== Benchmarks

[options="header"]
|===
| Method | Runtime | Mean | StdDev | Ratio | Allocated
| FirstOrDefault | .NET 7.0 | 5.373 ms | 0.1049 ms | 1.00 | 125 KB
| Find | .NET 7.0 | 1.691 ms | 0.0334 ms | 0.32 | 85.94 KB
| FirstOrDefault | .NET Framework 4.6.2 | 5.035 ms | 0.0421 ms | 1.00 | 125.38 KB
| Find | .NET Framework 4.6.2 | 1.779 ms | 0.0107 ms | 0.35 | 86.2 KB
|===

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

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

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

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

[Benchmark(Baseline = true)]
public void FirstOrDefault()
{
    for (var i = 0; i < N; i++)
    {
        var value = data[random.Next(N - 1)];
        _ = data.FirstOrDefault(x => x == value);   // Enumerable.FirstOrDefault()
    }
}

[Benchmark]
public void Find()
{
    for (var i = 0; i < N; i++)
    {
        var value = data[random.Next(N - 1)];
        _ = data.Find(x => x == value);             // List<T>.Find()
    }
}
----

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
  [Host]               : .NET Framework 4.8 (4.8.4614.0), X64 RyuJIT VectorSize=256
  .NET 7.0             : .NET 7.0.5 (7.0.523.17405), X64 RyuJIT AVX2
  .NET Framework 4.6.2 : .NET Framework 4.8 (4.8.4614.0), X64 RyuJIT VectorSize=256
----
