This commit is contained in:
mlemanczyk committed 2023-10-21 17:26:35 +02:00
1 parent 0159042755
commit ec69b1c406
38 files changed
+167 -181

No files matched your search

@@ -1,4 +1,6 @@
using BenchmarkDotNet.Attributes;
// Ignore Spelling: Poc
using BenchmarkDotNet.Attributes;
using System.Runtime.CompilerServices;
#pragma warning disable CA1822
@@ -7,14 +9,14 @@ namespace Recyclable.Collections.Benchmarks.POC
{
public class LessOperatorVsAndOperatorBenchmarks
{
private const int bitShift = 1 << 31;
private const int BitShift = 1 << 31;
private static readonly Random _rnd = new(1);
private static int num = -Math.Abs(_rnd.Next());
private static int _num = -Math.Abs(_rnd.Next());
public void Setup()
{
num = -1;
Console.WriteLine($"*** We're comparing if {num} is < 0 ***");
_num = -1;
Console.WriteLine($"*** We're comparing if {_num} is < 0 ***");
}
public void Cleanup() { }
@@ -30,25 +32,25 @@ namespace Recyclable.Collections.Benchmarks.POC
[Benchmark(Baseline = true)]
public void CompareWithLess()
{
DoNothing(num < 0);
DoNothing(_num < 0);
}
[Benchmark]
public void CompareWithAnd()
{
DoNothing((num & bitShift) != 0);
DoNothing((_num & BitShift) != 0);
}
[Benchmark]
public void CompareWithEqual()
{
DoNothing(num == -1);
DoNothing(_num == -1);
}
[Benchmark]
public void CompareToZero()
{
DoNothing(num == 0);
DoNothing(_num == 0);
}
}
}