rspec/rules/S6613/resources-dotnet.adoc
Gregory Paidis a69589504d
Modify rules S3260,S6610,S6612,S6613,S6617,S6618: Fix benchmark table (#3532)
* Fix benchmarks for S3260,S6610,S6612,S6613,S6617,S6618

* Review 1
2024-01-18 09:26:58 +01:00

70 lines
1.9 KiB
Plaintext

== Resources
=== Documentation
* https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.linkedlist-1[LinkedList<T>]
=== Benchmarks
[options="header"]
|===
| Method | Runtime | Mean | Standard Deviation | Allocated
| LastMethod | .NET 7.0 | 919,577,629.0 ns | 44,299,688.61 ns | 48504 B
| LastProperty | .NET 7.0 | 271.8 ns | 15.63 ns | -
| LastMethod | .NET Framework 4.6.2 | 810,316,427.1 ns | 47,768,482.31 ns | 57344 B
| LastProperty | .NET Framework 4.6.2 | 372.0 ns | 13.38 ns | -
|===
==== 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 LinkedList<int> data;
private Random random = new Random();
[Params(100_000)]
public int Size { get; set; }
[Params(1_000)]
public int Runs { get; set; }
[GlobalSetup]
public void Setup() =>
data = new LinkedList<int>(Enumerable.Range(0, Size).Select(x => random.Next()));
[Benchmark(Baseline = true)]
public void LastMethod()
{
for (var i = 0; i < Runs; i++)
{
_ = data.Last(); // Enumerable.Last()
}
}
[Benchmark]
public void LastProperty()
{
for (var i = 0; i < Runs; i++)
{
_ = data.Last; // Last property
}
}
----
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
----