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

@@ -8,26 +8,52 @@ namespace EvenPerfectBitScanner.Benchmarks;
[MemoryDiagnoser]
public class Mod128UIntBenchmarks
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint Mod128(uint value) => value & 127U;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint Mod128(uint value) => value & 127U;
[Params(3UL, 5UL, 6UL, 8UL, 10UL, 11UL, 32UL, 64UL, 128UL, 256UL, 2_047UL, 8_191UL, 65_535UL, 131_071UL, 2_147_483_647UL, uint.MaxValue - 1_024UL, uint.MaxValue - 511UL, uint.MaxValue - 255UL, uint.MaxValue - 127UL, uint.MaxValue - 63UL, uint.MaxValue - 31UL, uint.MaxValue - 17UL, uint.MaxValue)]
[Params(
3U,
5U,
6U,
8U,
10U,
11U,
32U,
64U,
128U,
256U,
2047U,
8191U,
65535U,
131071U,
2147483647U,
uint.MaxValue - 1024U,
uint.MaxValue - 511U,
uint.MaxValue - 255U,
uint.MaxValue - 127U,
uint.MaxValue - 63U,
uint.MaxValue - 31U,
uint.MaxValue - 17U,
uint.MaxValue)]
public uint Value { get; set; }
/// <summary>
/// Fastest most of the times. It's usually much faster than it's slower.
/// </summary>
/// <returns></returns>
[Benchmark(Baseline = true)]
/// <summary>
/// `% 128` baseline; BenchmarkDotNet reported near-empty-loop costs with means from 0.010-0.026 ns across the domain (e.g.
/// 0.0191 ns at value 3, 0.0136 ns at 5, 0.0170 ns at 32, 0.0108 ns at 256, 0.0138 ns at 2147483647).
/// </summary>
[Benchmark(Baseline = true)]
public uint ModuloOperator()
{
return Value % 128U;
}
/// <summary>
/// Bitmask helper that returns `value & 127`; generally matches the baseline at 0.006-0.023 ns (0.0163 ns at value 3, 0.0064 ns at
/// 6, 0.0152 ns at 10, 0.0156 ns at 2147483647) but regresses on 64 due to the benchmark harness (0.9496 ns, 67x slower).
/// </summary>
[Benchmark]
public uint ExtensionMethod()
{
return Mod128(Value);
}
}