-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathFixedTransformBenchmarks.cs
More file actions
74 lines (61 loc) · 2.6 KB
/
Copy pathFixedTransformBenchmarks.cs
File metadata and controls
74 lines (61 loc) · 2.6 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
using BenchmarkDotNet.Attributes;
namespace FixedMathSharp.Benchmarks;
/// <summary>
/// Measures allocation-free transform reads and mutations. Hierarchy reads are linear in depth.
/// </summary>
[MemoryDiagnoser]
public class FixedTransformBenchmarks
{
private readonly FixedTransform _root;
private readonly FixedTransform _depthEight;
private readonly FixedTransform _reparentParentA;
private readonly FixedTransform _reparentParentB;
private readonly FixedTransform _successfulChild;
private readonly FixedTransform _singularParent;
private readonly FixedTransform _failedChild;
public FixedTransformBenchmarks()
{
_root = new FixedTransform(
new Vector3d((Fixed64)1, (Fixed64)2, (Fixed64)3),
FixedQuaternion.FromAxisAngle(Vector3d.Up, Fixed64.PiOver4),
new Vector3d((Fixed64)2, (Fixed64)3, (Fixed64)4));
_depthEight = _root;
for (int i = 0; i < 8; i++)
{
_depthEight = new FixedTransform(
new Vector3d(Fixed64.One, Fixed64.Zero, Fixed64.One),
FixedQuaternion.Identity,
Vector3d.One,
_depthEight);
}
_reparentParentA = new FixedTransform(Vector3d.Right, FixedQuaternion.Identity, Vector3d.One);
_reparentParentB = new FixedTransform(Vector3d.Right, FixedQuaternion.Identity, Vector3d.One);
_successfulChild = new FixedTransform(
Vector3d.Forward,
FixedQuaternion.Identity,
Vector3d.One,
_reparentParentA);
_singularParent = new FixedTransform(Vector3d.Zero, FixedQuaternion.Identity, Vector3d.Zero);
_failedChild = new FixedTransform(Vector3d.Forward, FixedQuaternion.Identity, Vector3d.One);
}
[Benchmark]
public Fixed4x4 RootWorldMatrix() => _root.LocalToWorldMatrix;
[Benchmark]
public Vector3d RootWorldPosition() => _root.WorldPosition;
[Benchmark]
public FixedQuaternion RootWorldRotation() => _root.WorldRotation;
[Benchmark]
public Vector3d RootLossyScale() => _root.LossyScale;
[Benchmark]
public Fixed4x4 DepthEightWorldMatrix() => _depthEight.LocalToWorldMatrix;
[Benchmark]
public Vector3d DepthEightLossyScale() => _depthEight.LossyScale;
[Benchmark]
public bool SuccessfulReparent() =>
_successfulChild.TrySetParentKeepingWorld(
ReferenceEquals(_successfulChild.Parent, _reparentParentA)
? _reparentParentB
: _reparentParentA);
[Benchmark]
public bool FailedReparent() => _failedChild.TrySetParentKeepingWorld(_singularParent);
}