Benchmark results and TODOs added / updated

This commit is contained in:
Marek Lemańczyk committed 2025-10-02 15:00:30 +02:00
1 parent 507b9c91f4
commit f9e548279c
31 files changed
+581 -364

No files matched your search

@@ -9,31 +9,33 @@ namespace EvenPerfectBitScanner.Benchmarks;
[MemoryDiagnoser]
public class Mod3ULongBenchmarks
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static ulong Mod3(ulong value) =>
(
(uint)(value & ULongExtensions.WordBitMask) +
(uint)((value >> 16) & ULongExtensions.WordBitMask) +
(uint)((value >> 32) & ULongExtensions.WordBitMask) +
(uint)((value >> 48) & ULongExtensions.WordBitMask)
) % 3;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static ulong Mod3(ulong value) =>
((uint)(value & ULongExtensions.WordBitMask)
+ (uint)((value >> 16) & ULongExtensions.WordBitMask)
+ (uint)((value >> 32) & ULongExtensions.WordBitMask)
+ (uint)((value >> 48) & ULongExtensions.WordBitMask)) % 3UL;
[Params(3UL, 8191UL, 131071UL, 2147483647UL, ulong.MaxValue - 17UL)]
public ulong Value { get; set; }
/// <summary>
/// Fastest
/// </summary>
[Benchmark(Baseline = true)]
/// <summary>
/// `% 3` baseline; delivered 0.259-0.286 ns for the standard values (0.2640 ns at 3, 0.2599 ns at 8191, 0.2620 ns at 131071,
/// 0.2858 ns at 2147483647) and 0.4916 ns near ulong.Max.
/// </summary>
[Benchmark(Baseline = true)]
public ulong ModuloOperator()
{
return Value % 3UL;
}
/// <summary>
/// Byte-slice helper; measured 0.441 ns at value 3, 0.437 ns at 8191, 0.438 ns at 131071, 0.436 ns at 2147483647, and 0.448 ns
/// near ulong.Max—about 1.5-1.7x slower than the `%` baseline but still sub-nanosecond.
/// </summary>
[Benchmark]
public ulong ExtensionMethod()
{
return Mod3(Value);
}
}