Skip to content

Commit

Permalink
Modify rules S3260,S6610,S6612,S6613,S6617,S6618: Fix benchmark table (
Browse files Browse the repository at this point in the history
…#3532)

* Fix benchmarks for S3260,S6610,S6612,S6613,S6617,S6618

* Review 1
  • Loading branch information
gregory-paidis-sonarsource authored Jan 18, 2024
1 parent 24a9c85 commit a695895
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 30 deletions.
19 changes: 12 additions & 7 deletions rules/S3260/csharp/resources.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
17 changes: 11 additions & 6 deletions rules/S6610/resources-dotnet.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
16 changes: 11 additions & 5 deletions rules/S6612/resources-dotnet.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 7 additions & 1 deletion rules/S6613/resources-dotnet.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
24 changes: 15 additions & 9 deletions rules/S6617/resources-dotnet.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
12 changes: 10 additions & 2 deletions rules/S6618/csharp/rule.adoc
Original file line number Diff line number Diff line change
@@ -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<char>` 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<char>` 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.

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a695895

Please sign in to comment.