From a69589504d482ff39efbd123b01fa6cf4a4ca674 Mon Sep 17 00:00:00 2001 From: Gregory Paidis <115458417+gregory-paidis-sonarsource@users.noreply.github.com> Date: Thu, 18 Jan 2024 09:26:58 +0100 Subject: [PATCH] Modify rules S3260,S6610,S6612,S6613,S6617,S6618: Fix benchmark table (#3532) * Fix benchmarks for S3260,S6610,S6612,S6613,S6617,S6618 * Review 1 --- rules/S3260/csharp/resources.adoc | 19 ++++++++++++------- rules/S6610/resources-dotnet.adoc | 17 +++++++++++------ rules/S6612/resources-dotnet.adoc | 16 +++++++++++----- rules/S6613/resources-dotnet.adoc | 8 +++++++- rules/S6617/resources-dotnet.adoc | 24 +++++++++++++++--------- rules/S6618/csharp/rule.adoc | 12 ++++++++++-- 6 files changed, 66 insertions(+), 30 deletions(-) diff --git a/rules/S3260/csharp/resources.adoc b/rules/S3260/csharp/resources.adoc index c10a55ca37f..0c0423060f9 100644 --- a/rules/S3260/csharp/resources.adoc +++ b/rules/S3260/csharp/resources.adoc @@ -13,15 +13,20 @@ [options="header"] |=== -|Method | Runtime | Mean | StdDev | Ratio -| UnsealedType | .NET 5.0 | 918.7 us | 10.72 us | 1.00 -| SealedType | .NET 5.0 | 231.2 us | 3.20 us | 0.25 -| UnsealedType | .NET 6.0 | 867.9 us | 5.65 us | 1.00 -| SealedType | .NET 6.0 | 218.4 us | 0.59 us | 0.25 -| UnsealedType | .NET 7.0 | 1,074.5 us | 3.15 us | 1.00 -| SealedType | .NET 7.0 | 216.1 us | 1.19 us | 0.20 +| Method | Runtime | Mean | Standard Deviation +| UnsealedType | .NET 5.0 | 918.7 us | 10.72 us +| SealedType | .NET 5.0 | 231.2 us | 3.20 us +| UnsealedType | .NET 6.0 | 867.9 us | 5.65 us +| SealedType | .NET 6.0 | 218.4 us | 0.59 us +| UnsealedType | .NET 7.0 | 1,074.5 us | 3.15 us +| SealedType | .NET 7.0 | 216.1 us | 1.19 us |=== +==== Glossary + +* https://en.wikipedia.org/wiki/Arithmetic_mean[Mean] +* https://en.wikipedia.org/wiki/Standard_deviation[Standard Deviation] + The results were generated by running the following snippet with https://github.com/dotnet/BenchmarkDotNet[BenchmarkDotNet]: [source,csharp] diff --git a/rules/S6610/resources-dotnet.adoc b/rules/S6610/resources-dotnet.adoc index 5c41feafa93..6750ee13643 100644 --- a/rules/S6610/resources-dotnet.adoc +++ b/rules/S6610/resources-dotnet.adoc @@ -3,19 +3,24 @@ === Documentation * https://learn.microsoft.com/en-us/dotnet/api/system.string.startswith[string.StartsWith] -* https://learn.microsoft.com/en-us/dotnet/api/system.string.endswith[string.EndsWith] +* https://learn.microsoft.com/en-us/dotnet/api/system.string.endswith[string.EndsWith] === Benchmarks [options="header"] |=== -| Method | Mean | StdDev | Median -| StartsWith_String | 30.965 ms | 3.2732 ms | 29.932 ms -| StartsWith_Char | 7.568 ms | 0.3235 ms | 7.534 ms -| EndsWith_String | 30.421 ms | 5.1136 ms | 28.101 ms -| EndsWith_Char | 8.067 ms | 0.7092 ms | 7.935 ms +| Method | Mean | Standard Deviation +| StartsWith_String | 30.965 ms | 3.2732 ms +| StartsWith_Char | 7.568 ms | 0.3235 ms +| EndsWith_String | 30.421 ms | 5.1136 ms +| EndsWith_Char | 8.067 ms | 0.7092 ms |=== +==== Glossary + +* https://en.wikipedia.org/wiki/Arithmetic_mean[Mean] +* https://en.wikipedia.org/wiki/Standard_deviation[Standard Deviation] + The results were generated by running the following snippet with https://github.com/dotnet/BenchmarkDotNet[BenchmarkDotNet]: [source,csharp] diff --git a/rules/S6612/resources-dotnet.adoc b/rules/S6612/resources-dotnet.adoc index 998adb43912..63dc96c5230 100644 --- a/rules/S6612/resources-dotnet.adoc +++ b/rules/S6612/resources-dotnet.adoc @@ -10,13 +10,19 @@ [options="header"] |=== -| Method | Runtime | Median | StdDev | Ratio | Allocated -| Capture | .NET 7.0 | 68.81 ms | 4.432 ms | 1.00 | 88000063 B -| Lambda | .NET 7.0 | 40.76 ms | 3.724 ms | 0.59 | 50 B -| Capture | .NET Framework 4.6.2 | 75.92 ms | 5.239 ms | 1.00 | 88259787 B -| Lambda | .NET Framework 4.6.2 | 41.82 ms | 2.730 ms | 0.55 | - +| Method | Runtime | Mean | Standard Deviation | Allocated +| Capture | .NET 7.0 | 68.52 ms | 4.450 ms | 88000063 B +| Lambda | .NET 7.0 | 39.29 ms | 3.712 ms | 50 B +| Capture | .NET Framework 4.6.2 | 74.58 ms | 5.199 ms | 88259787 B +| Lambda | .NET Framework 4.6.2 | 42.03 ms | 2.752 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] diff --git a/rules/S6613/resources-dotnet.adoc b/rules/S6613/resources-dotnet.adoc index 4c13193a6de..bdbc430ed12 100644 --- a/rules/S6613/resources-dotnet.adoc +++ b/rules/S6613/resources-dotnet.adoc @@ -8,13 +8,19 @@ [options="header"] |=== -| Method | Runtime | Mean | StdDev | Allocated +| 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] diff --git a/rules/S6617/resources-dotnet.adoc b/rules/S6617/resources-dotnet.adoc index d9d6cc39323..63f69342343 100644 --- a/rules/S6617/resources-dotnet.adoc +++ b/rules/S6617/resources-dotnet.adoc @@ -16,17 +16,23 @@ [options="header"] |=== -| Method | Runtime | Mean | StdDev | Allocated -| HashSet_Any | .NET 7.0 | 35,388.333 us | 620.1863 us | 40132 B -| HashSet_Contains | .NET 7.0 | 3.799 us | 0.1489 us | - -| List_Any | .NET 7.0 | 32,851.509 us | 667.1658 us | 40130 B -| List_Contains | .NET 7.0 | 375.132 us | 8.0764 us | - -| HashSet_Any | .NET Framework 4.6.2 | 28,979.763 us | 678.0093 us | 40448 B -| HashSet_Contains | .NET Framework 4.6.2 | 5.987 us | 0.1090 us | - -| List_Any | .NET Framework 4.6.2 | 25,830.221 us | 487.2470 us | 40448 B -| List_Contains | .NET Framework 4.6.2 | 5,935.812 us | 57.7569 us | - +| Method | Runtime | Mean | Standard Deviation | Allocated +| HashSet_Any | .NET 7.0 | 35,388.333 us | 620.1863 us | 40132 B +| HashSet_Contains | .NET 7.0 | 3.799 us | 0.1489 us | - +| List_Any | .NET 7.0 | 32,851.509 us | 667.1658 us | 40130 B +| List_Contains | .NET 7.0 | 375.132 us | 8.0764 us | - +| HashSet_Any | .NET Framework 4.6.2 | 28,979.763 us | 678.0093 us | 40448 B +| HashSet_Contains | .NET Framework 4.6.2 | 5.987 us | 0.1090 us | - +| List_Any | .NET Framework 4.6.2 | 25,830.221 us | 487.2470 us | 40448 B +| List_Contains | .NET Framework 4.6.2 | 5,935.812 us | 57.7569 us | - |=== +==== 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] diff --git a/rules/S6618/csharp/rule.adoc b/rules/S6618/csharp/rule.adoc index 7f0d1c4d9b2..14a71684522 100644 --- a/rules/S6618/csharp/rule.adoc +++ b/rules/S6618/csharp/rule.adoc @@ -1,6 +1,6 @@ == Why is this an issue? -In order to produce a formatted string, both `string.Create` and either `FormattableString.Invariant` or `FormattableString.CurrentCulture` can be used. However, `string.Create` rents array buffers from `ArrayPool` making it more performant, as well as preventing unnecessary allocations and future stress on the Garbage Collector. +In order to produce a formatted string, both `string.Create` and either `FormattableString.Invariant` or `FormattableString.CurrentCulture` can be used. However, `string.Create` rents array buffers from `ArrayPool` making it more performant, as well as preventing unnecessary allocations and future stress on the Garbage Collector. This applies to .NET versions after .NET 6, when these `string.Create` overloads were introduced. @@ -63,11 +63,19 @@ The results were generated by running the following snippet with https://github. [options="header"] |=== -| Method | Runtime | Mean | StdDev | Allocated +| Method | Runtime | Mean | Standard Deviation | Allocated | StringCreate | .NET 7.0 | 152.5 ms | 3.09 ms | 83.92 MB | FormattableString | .NET 7.0 | 191.8 ms | 6.92 ms | 198.36 MB |=== +==== 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] ---- int Value = 42;