-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathMatrix4x4Benchmarks.cs
More file actions
150 lines (124 loc) · 4.4 KB
/
Matrix4x4Benchmarks.cs
File metadata and controls
150 lines (124 loc) · 4.4 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
using BenchmarkDotNet.Attributes;
namespace FixedMathSharp.Benchmarks;
[MemoryDiagnoser]
public class Matrix4x4Benchmarks
{
private readonly Fixed4x4[] _matrices = BenchmarkFixtures.Matrices;
private readonly Fixed4x4[] _perspectiveMatrices = BenchmarkFixtures.PerspectiveMatrices;
private readonly FixedQuaternion[] _rotations = BenchmarkFixtures.RotationsA;
private readonly Vector3d[] _points = BenchmarkFixtures.VectorsA;
private readonly Vector3d[] _scales = BenchmarkFixtures.Scales;
private readonly Vector3d[] _translations = BenchmarkFixtures.Translations;
[Benchmark]
public Fixed4x4 CreateTranslation()
{
Fixed4x4 accumulator = Fixed4x4.Identity;
for (int i = 0; i < _points.Length; i++)
accumulator = accumulator * Fixed4x4.CreateTranslation(_translations[i]);
return accumulator;
}
[Benchmark]
public Fixed4x4 CreateRotation()
{
Fixed4x4 accumulator = Fixed4x4.Identity;
for (int i = 0; i < _rotations.Length; i++)
accumulator = accumulator * Fixed4x4.CreateRotation(_rotations[i]);
return accumulator;
}
[Benchmark]
public Fixed4x4 CreateScale()
{
Fixed4x4 accumulator = Fixed4x4.Identity;
for (int i = 0; i < _scales.Length; i++)
accumulator = accumulator * Fixed4x4.CreateScale(_scales[i]);
return accumulator;
}
[Benchmark]
public Fixed4x4 CreateTransform()
{
Fixed4x4 accumulator = Fixed4x4.Identity;
for (int i = 0; i < _points.Length; i++)
accumulator = accumulator * Fixed4x4.CreateTransform(_translations[i], _rotations[i], _scales[i]);
return accumulator;
}
[Benchmark]
public Fixed4x4 ScaleRotateTranslate()
{
Fixed4x4 accumulator = Fixed4x4.Identity;
for (int i = 0; i < _points.Length; i++)
accumulator = accumulator * Fixed4x4.ScaleRotateTranslate(_translations[i], _rotations[i], _scales[i]);
return accumulator;
}
[Benchmark]
public Fixed4x4 TranslateRotateScale()
{
Fixed4x4 accumulator = Fixed4x4.Identity;
for (int i = 0; i < _points.Length; i++)
accumulator = accumulator * Fixed4x4.TranslateRotateScale(_translations[i], _rotations[i], _scales[i]);
return accumulator;
}
[Benchmark]
public Fixed4x4 Multiply()
{
Fixed4x4 accumulator = Fixed4x4.Identity;
for (int i = 0; i < _matrices.Length; i++)
accumulator = accumulator * _matrices[i];
return accumulator;
}
[Benchmark]
public Vector3d TransformPoint()
{
Vector3d accumulator = Vector3d.Zero;
for (int i = 0; i < _matrices.Length; i++)
accumulator += Fixed4x4.TransformPoint(_matrices[i], _points[i]);
return accumulator;
}
[Benchmark]
public Fixed64 ExtractRotation()
{
Fixed64 accumulator = Fixed64.Zero;
for (int i = 0; i < _matrices.Length; i++)
{
FixedQuaternion rotation = Fixed4x4.ExtractRotation(_matrices[i]);
accumulator += rotation.X + rotation.Y + rotation.Z + rotation.W;
}
return accumulator;
}
[Benchmark]
public Fixed64 Decompose()
{
Fixed64 accumulator = Fixed64.Zero;
for (int i = 0; i < _matrices.Length; i++)
{
if (Fixed4x4.Decompose(_matrices[i], out Vector3d translation, out FixedQuaternion rotation, out Vector3d scale))
{
accumulator += scale.X + scale.Y + scale.Z;
accumulator += rotation.X + rotation.Y + rotation.Z + rotation.W;
accumulator += translation.X + translation.Y + translation.Z;
}
}
return accumulator;
}
[Benchmark]
public Fixed4x4 InvertAffine()
{
Fixed4x4 accumulator = Fixed4x4.Identity;
for (int i = 0; i < _matrices.Length; i++)
{
if (Fixed4x4.Invert(_matrices[i], out Fixed4x4 inverse))
accumulator = accumulator * inverse;
}
return accumulator;
}
[Benchmark]
public Fixed4x4 InvertFull()
{
Fixed4x4 accumulator = Fixed4x4.Identity;
for (int i = 0; i < _perspectiveMatrices.Length; i++)
{
if (Fixed4x4.Invert(_perspectiveMatrices[i], out Fixed4x4 inverse))
accumulator = accumulator * inverse;
}
return accumulator;
}
}