-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathMatrix3x3Benchmarks.cs
More file actions
73 lines (61 loc) · 2.15 KB
/
Matrix3x3Benchmarks.cs
File metadata and controls
73 lines (61 loc) · 2.15 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
using BenchmarkDotNet.Attributes;
namespace FixedMathSharp.Benchmarks;
[MemoryDiagnoser]
public class Matrix3x3Benchmarks
{
private readonly Fixed64[] _angles = BenchmarkFixtures.Angles;
private readonly Vector3d[] _directions = BenchmarkFixtures.NormalizedAxes;
private readonly Fixed3x3[] _matrices = BenchmarkFixtures.Matrix3s;
[Benchmark]
public Fixed3x3 CreateRotation()
{
Fixed3x3 accumulator = Fixed3x3.Identity;
for (int i = 0; i < _angles.Length; i++)
{
Fixed64 pitch = _angles[(i + 7) & (BenchmarkFixtures.SampleCount - 1)] * Fixed64.Quarter;
Fixed64 yaw = _angles[(i + 13) & (BenchmarkFixtures.SampleCount - 1)] * Fixed64.Quarter;
Fixed64 roll = _angles[(i + 29) & (BenchmarkFixtures.SampleCount - 1)] * Fixed64.Quarter;
accumulator =
accumulator *
Fixed3x3.CreateRotationY(yaw) *
Fixed3x3.CreateRotationX(pitch) *
Fixed3x3.CreateRotationZ(roll);
}
return accumulator;
}
[Benchmark]
public Fixed3x3 Multiply()
{
Fixed3x3 accumulator = Fixed3x3.Identity;
for (int i = 0; i < _matrices.Length; i++)
accumulator = accumulator * _matrices[i];
return accumulator;
}
[Benchmark]
public Vector3d TransformDirection()
{
Vector3d accumulator = Vector3d.Zero;
for (int i = 0; i < _matrices.Length; i++)
accumulator += Fixed3x3.TransformDirection(_matrices[i], _directions[i]);
return accumulator;
}
[Benchmark]
public Fixed64 Determinant()
{
Fixed64 accumulator = Fixed64.Zero;
for (int i = 0; i < _matrices.Length; i++)
accumulator += _matrices[i].GetDeterminant();
return accumulator;
}
[Benchmark]
public Fixed3x3 Invert()
{
Fixed3x3 accumulator = Fixed3x3.Identity;
for (int i = 0; i < _matrices.Length; i++)
{
if (Fixed3x3.Invert(_matrices[i], out Fixed3x3? inverse) && inverse.HasValue)
accumulator = accumulator * inverse.Value;
}
return accumulator;
}
}