Benchmarks for static bit masks added.

This commit is contained in:
mlemanczyk committed 2026-01-25 01:25:53 +01:00
1 parent 38b83a3d55
commit f864e73f67
1 file changed
+28
@@ -198,6 +198,21 @@ namespace EvenPerfectBitScanner.Benchmarks
_ => throw new ArgumentOutOfRangeException(nameof(i)),
};
private static readonly ulong[] BitMask64 = CreateBitMask64();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static ulong[] CreateBitMask64()
{
ulong[] masks = new ulong[64];
ulong value = 1UL;
for (int i = 0; i < 64; i++)
{
masks[i] = value;
value <<= 1;
}
return masks;
}
[Benchmark(Baseline = true)]
public ulong ByShifting()
{
@@ -221,6 +236,19 @@ namespace EvenPerfectBitScanner.Benchmarks
return result;
}
[Benchmark]
public ulong StaticArray()
{
ulong result = 0UL;
ulong[] bitMask64 = BitMask64;
for (int i = 0; i <= 63; i++)
{
result = bitMask64[i];
}
return result;
}
}
public class Pow2ProviderLongBenchmarks