-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathFixedRangeBenchmarks.cs
More file actions
117 lines (97 loc) · 3.05 KB
/
FixedRangeBenchmarks.cs
File metadata and controls
117 lines (97 loc) · 3.05 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using BenchmarkDotNet.Attributes;
namespace FixedMathSharp.Benchmarks;
[MemoryDiagnoser]
public class FixedRangeBenchmarks
{
private readonly Fixed64[] _scalars = BenchmarkFixtures.ScalarsA;
private readonly FixedRange[] _rangesA = BenchmarkFixtures.RangesA;
private readonly FixedRange[] _rangesB = BenchmarkFixtures.RangesB;
private readonly Vector3d[] _origins = BenchmarkFixtures.NormalizedAxes;
[Benchmark]
public int InRangeExclusive()
{
int count = 0;
for (int i = 0; i < _rangesA.Length; i++)
{
if (_rangesA[i].InRange(_scalars[i]))
count++;
}
return count;
}
[Benchmark]
public int InRangeInclusive()
{
int count = 0;
for (int i = 0; i < _rangesA.Length; i++)
{
if (_rangesA[i].InRange(_scalars[i], includeMax: true))
count++;
}
return count;
}
[Benchmark]
public int Overlaps()
{
int count = 0;
for (int i = 0; i < _rangesA.Length; i++)
{
if (_rangesA[i].Overlaps(_rangesB[i]))
count++;
}
return count;
}
[Benchmark]
public Fixed64 GetDirection()
{
Fixed64 accumulator = Fixed64.Zero;
for (int i = 0; i < _rangesA.Length; i++)
{
if (FixedRange.GetDirection(_rangesA[i], _rangesB[i], out Fixed64? sign) && sign.HasValue)
accumulator += sign.Value;
}
return accumulator;
}
[Benchmark]
public Fixed64 ComputeOverlapDepth()
{
Fixed64 accumulator = Fixed64.Zero;
for (int i = 0; i < _rangesA.Length; i++)
accumulator += FixedRange.ComputeOverlapDepth(_rangesA[i], _rangesB[i]);
return accumulator;
}
[Benchmark]
public Vector3d CheckOverlap()
{
Vector3d accumulator = Vector3d.Zero;
for (int i = 0; i < _rangesA.Length; i++)
{
if (FixedRange.CheckOverlap(_origins[i], _rangesA[i], _rangesB[i], Fixed64.MaxValue, Fixed64.One, out (Vector3d Vector, Fixed64 Depth)? output) && output.HasValue)
accumulator += output.Value.Vector + new Vector3d(output.Value.Depth, output.Value.Depth, output.Value.Depth);
}
return accumulator;
}
[Benchmark]
public FixedRange Add()
{
FixedRange accumulator = new(Fixed64.Zero, Fixed64.Zero);
for (int i = 0; i < _rangesA.Length; i++)
accumulator += _rangesA[i] + _rangesB[i];
return accumulator;
}
[Benchmark]
public FixedRange Subtract()
{
FixedRange accumulator = new(Fixed64.Zero, Fixed64.Zero);
for (int i = 0; i < _rangesA.Length; i++)
accumulator += _rangesA[i] - _rangesB[i];
return accumulator;
}
[Benchmark]
public FixedRange AddInPlace()
{
FixedRange accumulator = new(Fixed64.Zero, Fixed64.Zero);
for (int i = 0; i < _rangesA.Length; i++)
accumulator.AddInPlace(_rangesA[i].Length);
return accumulator;
}
}