Benchmarks for static bit masks added.
This commit is contained in:
1 parent
38b83a3d55
commit
f864e73f67
1 file changed
+28
@@ -198,6 +198,21 @@ namespace EvenPerfectBitScanner.Benchmarks
|
|||||||
_ => throw new ArgumentOutOfRangeException(nameof(i)),
|
_ => 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)]
|
[Benchmark(Baseline = true)]
|
||||||
public ulong ByShifting()
|
public ulong ByShifting()
|
||||||
{
|
{
|
||||||
@@ -221,6 +236,19 @@ namespace EvenPerfectBitScanner.Benchmarks
|
|||||||
|
|
||||||
return result;
|
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
|
public class Pow2ProviderLongBenchmarks
|
||||||
|
|||||||
Reference in new issue
Block a user