Extension methods benchmarked. Slower alternatives replaced.
This commit is contained in:
1 parent
9becb8df67
commit
6e99ee39e3
40 files changed
+930
-1026
No files matched your search
@@ -1,3 +1,4 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using BenchmarkDotNet.Jobs;
|
||||
using PerfectNumbers.Core;
|
||||
@@ -8,10 +9,22 @@ namespace EvenPerfectBitScanner.Benchmarks;
|
||||
[MemoryDiagnoser]
|
||||
public class Mod5ULongBenchmarks
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static ulong Mod5(ulong value) =>
|
||||
(
|
||||
(uint)(value & ULongExtensions.WordBitMask) +
|
||||
(uint)((value >> 16) & ULongExtensions.WordBitMask) +
|
||||
(uint)((value >> 32) & ULongExtensions.WordBitMask) +
|
||||
(uint)((value >> 48) & ULongExtensions.WordBitMask)
|
||||
) % 5;
|
||||
|
||||
[Params(5UL, 8191UL, 131071UL, 2147483647UL, ulong.MaxValue - 31UL)]
|
||||
public ulong Value { get; set; }
|
||||
|
||||
[Benchmark(Baseline = true)]
|
||||
/// <summary>
|
||||
/// Fastest
|
||||
/// </summary>
|
||||
[Benchmark(Baseline = true)]
|
||||
public ulong ModuloOperator()
|
||||
{
|
||||
return Value % 5UL;
|
||||
@@ -20,7 +33,7 @@ public class Mod5ULongBenchmarks
|
||||
[Benchmark]
|
||||
public ulong ExtensionMethod()
|
||||
{
|
||||
return Value.Mod5();
|
||||
return Mod5(Value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user