Skip to content

Commit

Permalink
Deploying to gh-pages from @ 8536b27 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-strecker-sonarsource committed Jan 9, 2025
1 parent dd7a897 commit 613e92d
Show file tree
Hide file tree
Showing 3 changed files with 435 additions and 1 deletion.
217 changes: 217 additions & 0 deletions rules/S3247/csharp-description.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,227 @@ <h3 id="_documentation">Documentation</h3>
</li>
</ul>
</div>
</div>
<div class="sect2">
<h3 id="_benchmarks">Benchmarks</h3>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 25%;">
<col style="width: 25%;">
<col style="width: 25%;">
<col style="width: 25%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Method</th>
<th class="tableblock halign-left valign-top">Runtime</th>
<th class="tableblock halign-left valign-top">Mean</th>
<th class="tableblock halign-left valign-top">Standard Deviation</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">IsPattern_Class</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">.NET 9.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">176.48 ns</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0.765 ns</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">IsWithCast_Class</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">.NET 9.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">246.12 ns</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">22.391 ns</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">IsPattern_Class</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">.NET Framework 4.8.1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">325.11 ns</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">14.435 ns</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">IsWithCast_Class</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">.NET Framework 4.8.1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">311.22 ns</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">11.145 ns</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">IsPattern_Interface</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">.NET 9.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">26.77 ns</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1.123 ns</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">IsWithCast_Interface</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">.NET 9.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">26.45 ns</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2.115 ns</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">IsPattern_Interface</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">.NET Framework 4.8.1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">119.80 ns</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">5.411 ns</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">IsWithCast_Interface</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">.NET Framework 4.8.1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">119.33 ns</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">4.380 ns</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">IsPattern_ValueType</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">.NET 9.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">22.58 ns</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1.161 ns</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">IsWithCast_ValueType</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">.NET 9.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">19.41 ns</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2.675 ns</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">IsPattern_ValueType</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">.NET Framework 4.8.1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">39.66 ns</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0.645 ns</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">IsWithCast_ValueType</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">.NET Framework 4.8.1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">41.34 ns</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0.462 ns</p></td>
</tr>
</tbody>
</table>
<div class="sect3">
<h4 id="_glossary">Glossary</h4>
<div class="ulist">
<ul>
<li>
<p><a href="https://en.wikipedia.org/wiki/Arithmetic_mean">Mean</a></p>
</li>
<li>
<p><a href="https://en.wikipedia.org/wiki/Standard_deviation">Standard Deviation</a></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The results were generated by running the following snippet with <a href="https://github.com/dotnet/BenchmarkDotNet">BenchmarkDotNet</a>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-csharp" data-lang="csharp">private Random random = new Random(1);

private object ReturnSometimes&lt;T&gt;() where T : new() =&gt;
random.Next(2) switch
{
0 =&gt; new T(),
1 =&gt; new object(),
};

[BenchmarkCategory("ValueType"), Benchmark(Baseline = true)]
public int IsPattern_ValueType()
{
var i = ReturnSometimes&lt;int&gt;();
return i is int d
? d
: default;
}

[BenchmarkCategory("ValueType"), Benchmark]
public int IsWithCast_ValueType()
{
var i = ReturnSometimes&lt;int&gt;();
return i is int
? (int)i
: default;
}

[BenchmarkCategory("Class"), Benchmark(Baseline = true)]
public DuplicateCasts IsPattern_Class()
{
var i = ReturnSometimes&lt;DuplicateCasts&gt;();
return i is DuplicateCasts d
? d
: default;
}

[BenchmarkCategory("Class"), Benchmark]
public DuplicateCasts IsWithCast_Class()
{
var i = ReturnSometimes&lt;DuplicateCasts&gt;();
return i is DuplicateCasts
? (DuplicateCasts)i
: default;
}

[BenchmarkCategory("Interface"), Benchmark(Baseline = true)]
public IReadOnlyList&lt;int&gt; IsPattern_Interface()
{
var i = ReturnSometimes&lt;List&lt;int&gt;&gt;();
return i is IReadOnlyList&lt;int&gt; d
? d
: default;
}

[BenchmarkCategory("Interface"), Benchmark]
public IReadOnlyList&lt;int&gt; IsWithCast_Interface()
{
var i = ReturnSometimes&lt;List&lt;int&gt;&gt;();
return i is IReadOnlyList&lt;int&gt;
? (IReadOnlyList&lt;int&gt;)i
: default;
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Hardware configuration:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code>BenchmarkDotNet v0.14.0, Windows 10 (10.0.19045.5247/22H2/2022Update)
Intel Core Ultra 7 165H, 1 CPU, 22 logical and 16 physical cores
[Host] : .NET Framework 4.8.1 (4.8.9282.0), X64 RyuJIT VectorSize=256
.NET 9.0 : .NET 9.0.0 (9.0.24.52809), X64 RyuJIT AVX2
.NET Framework 4.8.1 : .NET Framework 4.8.1 (4.8.9282.0), X64 RyuJIT VectorSize=256</code></pre>
</div>
</div>
<hr>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_implementation_specification">Implementation Specification</h2>
<div class="sectionbody">
Expand Down
Loading

0 comments on commit 613e92d

Please sign in to comment.