-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathPointAnchorBenchmarks.cs
More file actions
112 lines (101 loc) · 3.72 KB
/
Copy pathPointAnchorBenchmarks.cs
File metadata and controls
112 lines (101 loc) · 3.72 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
using BenchmarkDotNet.Attributes;
using FixedMathSharp.Geometry;
namespace FixedMathSharp.Benchmarks;
/// <summary>
/// Measures exact point-anchor materialization and frame re-expression used by
/// collision and query loops.
/// </summary>
[MemoryDiagnoser]
public class PointAnchorBenchmarks
{
private readonly FixedPointAnchor _sameFrameIdentity = new(
new Vector3d(5, -3, 7),
FixedQuaternion.Identity,
new Vector3d(2, 1, -4),
new Vector3d(Fixed64.Half, -Fixed64.Half, Fixed64.One));
private readonly FixedPointAnchor _sameFrameIdentityOther = new(
new Vector3d(5, -3, 7),
FixedQuaternion.Identity,
new Vector3d(-2, 4, 1));
private readonly FixedPointAnchor _identityFrameOtherOrigin = new(
new Vector3d(-1, 4, 3),
FixedQuaternion.Identity,
new Vector3d(-2, 4, 1));
private readonly FixedPointAnchor _sameFrameRotated = new(
new Vector3d(5, -3, 7),
FixedQuaternion.FromAxisAngle(Vector3d.Up, Fixed64.PiOver4),
new Vector3d(2, 1, -4),
new Vector3d(Fixed64.Half, -Fixed64.Half, Fixed64.One));
private readonly FixedPointAnchor _sameFrameRotatedOther = new(
new Vector3d(5, -3, 7),
FixedQuaternion.FromAxisAngle(Vector3d.Up, Fixed64.PiOver4),
new Vector3d(-2, 4, 1));
private readonly FixedPointAnchor _anchor = new(
new Vector3d(5, -3, 7),
FixedQuaternion.FromAxisAngle(Vector3d.Up, Fixed64.PiOver4),
new Vector3d(2, 1, -4),
new Vector3d(Fixed64.Half, -Fixed64.Half, Fixed64.One));
private readonly Vector3d _frameOrigin = new(1, 2, 3);
private readonly FixedQuaternion _frameRotation =
FixedQuaternion.FromAxisAngle(Vector3d.Right, Fixed64.PiOver4);
private readonly FixedPointAnchor _other = new(
new Vector3d(1, 2, 3),
FixedQuaternion.FromAxisAngle(Vector3d.Right, Fixed64.PiOver4),
new Vector3d(-2, 4, 1),
new Vector3d(-Fixed64.Half, Fixed64.One, Fixed64.Half));
private readonly FixedPointAnchor2d _anchor2d = new(
new Vector2d(5, -3),
Fixed64.PiOver3,
new Vector2d(2, 1),
new Vector2d(-Fixed64.Half, Fixed64.FromFraction(1, 4)));
private readonly FixedPointAnchor2d _other2d = new(
new Vector2d(1, 2),
-Fixed64.PiOver4,
new Vector2d(-2, 4),
new Vector2d(Fixed64.Half, -Fixed64.One));
[Benchmark(Baseline = true)]
public bool MaterializeWorldPoint() =>
_anchor.TryGetPoint(out _);
[Benchmark]
public bool ReexpressInRigidFrame() =>
_anchor.TryGetLocalPointIn(
_frameOrigin,
_frameRotation,
out _);
[Benchmark]
public bool ScaledRelativeOffset() =>
_anchor.TryGetScaledOffsetFrom(
_other,
Fixed64.Half,
out _);
[Benchmark]
public bool ProjectedRelativeOffset() =>
_anchor.TryGetProjectedOffsetFrom(
_other,
Vector3d.Right,
out _);
[Benchmark]
public bool RelativeOffset2d() =>
_anchor2d.TryGetOffsetFrom(_other2d, out _);
[Benchmark]
public bool SameFrameIdentityOffset() =>
_sameFrameIdentity.TryGetOffsetFrom(
_sameFrameIdentityOther,
out _);
[Benchmark]
public bool IdentityFrameOffset() =>
_sameFrameIdentity.TryGetOffsetFrom(
_identityFrameOtherOrigin,
out _);
[Benchmark]
public bool SameFrameRotatedOffset() =>
_sameFrameRotated.TryGetOffsetFrom(
_sameFrameRotatedOther,
out _);
[Benchmark]
public bool ReexpressInRotatedFrame2d() =>
_anchor2d.TryGetLocalPointIn(
_other2d.Origin,
_other2d.Rotation,
out _);
}