-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathWideRawRatioBenchmarks.cs
More file actions
65 lines (53 loc) · 2.12 KB
/
Copy pathWideRawRatioBenchmarks.cs
File metadata and controls
65 lines (53 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using BenchmarkDotNet.Attributes;
namespace FixedMathSharp.Benchmarks;
[MemoryDiagnoser]
public class WideRawRatioBenchmarks
{
private readonly Signed576 _oneWordNumerator = Positive(0UL, 123_456_789UL);
private readonly Signed576 _oneWordDenominator = Positive(0UL, 97UL);
private readonly Signed576 _twoWordNumeratorFor32Bit =
Positive(1UL, 0x1234_5678_9ABC_DEF0UL);
private readonly Signed576 _denominator32Bit = Positive(0UL, uint.MaxValue);
private readonly Signed576 _twoWordNumeratorFor64Bit =
Positive(0x1000_0000_0000_0000UL, 0x1234_5678_9ABC_DEF0UL);
private readonly Signed576 _denominator64Bit =
Positive(0UL, 0xF000_0000_0000_0001UL);
private readonly Signed576 _unrepresentableNumerator = Positive(1UL, 0UL);
private readonly Signed576 _unitDenominator = Positive(0UL, 1UL);
private readonly Signed576 _multiWordNumerator =
Positive(3UL, 0x1234_5678_9ABC_DEF0UL);
private readonly Signed576 _multiWordDenominator =
Positive(1UL, 0xFEDC_BA98_7654_3210UL);
[Benchmark]
public bool OneWordNumeratorAndDenominator() =>
Fixed64.TryGetSignedRawRatio(
_oneWordNumerator,
_oneWordDenominator,
out _);
[Benchmark]
public bool TwoWordNumeratorAnd32BitDenominator() =>
Fixed64.TryGetSignedRawRatio(
_twoWordNumeratorFor32Bit,
_denominator32Bit,
out _);
[Benchmark]
public bool TwoWordNumeratorAnd64BitDenominator() =>
Fixed64.TryGetSignedRawRatio(
_twoWordNumeratorFor64Bit,
_denominator64Bit,
out _);
[Benchmark]
public bool UnrepresentableQuotient() =>
Fixed64.TryGetSignedRawRatio(
_unrepresentableNumerator,
_unitDenominator,
out _);
[Benchmark(Baseline = true)]
public bool MultiWordDenominatorControl() =>
Fixed64.TryGetSignedRawRatio(
_multiWordNumerator,
_multiWordDenominator,
out _);
private static Signed576 Positive(ulong high, ulong low) =>
new(0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, high, low);
}