-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbench_test.go
More file actions
73 lines (55 loc) · 1.45 KB
/
bench_test.go
File metadata and controls
73 lines (55 loc) · 1.45 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
package math
import (
"math"
"testing"
)
var vkngMathOutVec4 Vec4[float32]
var vkngMathOutVec3 Vec3[float32]
var vkngMathOutQuat Quaternion[float32]
func BenchmarkTransformVec4VkngMath(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
var mat Mat4x4[float32]
mat.SetIdentity()
mat.Translate(1, 1, 1)
mat.RotateY(1)
mat.Scale(1.5, 1.5, 1.5)
transform := Vec4[float32]{5, 10, 15, 1}
transform.Transform(&mat)
vkngMathOutVec4 = transform
}
}
func BenchmarkRotateVec3VkngMath(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
transform := Vec3[float32]{5, 10, 15}
axis := Vec3[float32]{1, 0, 0}
transform.Rotate(math.Pi, &axis)
vkngMathOutVec3 = transform
}
}
func BenchmarkRotateQuaternionVkngMath(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
transform := Vec3[float32]{5, 10, 15}
var quat Quaternion[float32]
quat.SetRotationEulers(0, math.Pi, math.Pi/2)
transform.RotateWithQuaternion(&quat)
vkngMathOutQuat = quat
}
}
func BenchmarkMatrixMultTransformVkngMath(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
var translateMat, rotateMat, scaleMat Mat4x4[float32]
translateMat.SetTranslation(1, 1, 1)
rotateMat.SetRotationY(1)
scaleMat.SetScale(1.5, 1.5, 1.5)
var mat Mat4x4[float32]
mat.SetMultMat4x4(&translateMat, &rotateMat)
mat.MultMat4x4(&scaleMat)
transform := Vec4[float32]{5, 10, 15, 1}
transform.Transform(&mat)
vkngMathOutVec4 = transform
}
}