rspec/rules/S6603/resources-dotnet.adoc

70 lines
2.2 KiB
Plaintext

== Resources
=== Documentation
* https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.trueforall[List<T>.TrueForAll(Predicate<T>)]
* https://learn.microsoft.com/en-us/dotnet/api/system.array.trueforall[Array.TrueForAll<T>(T[\], Predicate<T>)]
* https://learn.microsoft.com/en-us/dotnet/api/system.collections.immutable.immutablelist-1.trueforall[ImmutableList<T>.TrueForAll(Predicate<T>)]
* https://learn.microsoft.com/en-us/dotnet/api/system.collections.immutable.immutablelist-1.builder.trueforall[ImmutableList<T>.Builder.TrueForAll(Predicate<T>)]
* https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.all[Enumerable.All<TSource>]
=== Benchmarks
[options="header"]
|===
| Method | Runtime | Mean | Standard Deviation | Allocated
| TrueForAll | .NET 7.0 | 1.302 ms | 0.0027 ms | 1 B
| All | .NET 7.0 | 6.279 ms | 0.0181 ms | 40004 B
| TrueForAll | .NET Framework 4.6.2 | 1.105 ms | 0.0142 ms | -
| All | .NET Framework 4.6.2 | 4.968 ms | 0.0143 ms | 40128 B
|===
==== 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<int> data;
[Params(10_000)]
public int N { get; set; }
[GlobalSetup]
public void Setup() =>
data = Enumerable.Range(0, N).Select(x => 42).ToList();
[Benchmark]
public void TrueForAll()
{
for (var i = 0; i < N; i++)
{
_ = data.TrueForAll(x => x == 42); // List<T>.TrueForAll
}
}
[Benchmark(Baseline = true)]
public void All()
{
for (var i = 0; i < N; i++)
{
_ = data.All(x => x == 42); // Enumerable.All<TSource>
}
}
----
Hardware configuration:
[source]
----
BenchmarkDotNet=v0.13.5, OS=Windows 10 (10.0.19045.2846/22H2/2022Update)
12th Gen Intel Core i7-12800H, 1 CPU, 20 logical and 14 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 (4.8.4614.0), X64 RyuJIT VectorSize=256
----