11#include < benchmark/benchmark.h>
22#include < vector_math/matrix4.hpp>
3+ #include < vector_math/matrix4f.hpp>
34
45#include < glm/vec3.hpp> // glm::vec3
56#include < glm/vec4.hpp> // glm::vec4
89#include < glm/ext/matrix_clip_space.hpp> // glm::perspective
910#include < glm/ext/scalar_constants.hpp>
1011
12+ using namespace systems ::leal::vector_math;
13+
1114// dummy
1215static void BM_StringCreation (benchmark::State& state) {
1316 for (auto _ : state)
@@ -18,47 +21,92 @@ BENCHMARK(BM_StringCreation);
1821// /////////////////////
1922// Matrix4 benchmark //
2023// /////////////////////
21- static void BM_MatrixCreation (benchmark::State& state) {
24+ static void BM_Matrix4Creation (benchmark::State& state) {
2225 for (auto _ : state){
2326 benchmark::DoNotOptimize (systems::leal::vector_math::Matrix4<float >());
2427 }
2528}
26- BENCHMARK (BM_MatrixCreation );
29+ BENCHMARK (BM_Matrix4Creation );
2730
28- static void BM_MatrixIdentity (benchmark::State& state) {
31+ static void BM_Matrix4Identity (benchmark::State& state) {
2932 for (auto _ : state){
3033 benchmark::DoNotOptimize (systems::leal::vector_math::Matrix4<float >::identity ());
3134 }
3235}
33- BENCHMARK (BM_MatrixIdentity );
36+ BENCHMARK (BM_Matrix4Identity );
3437
35- static void BM_MatrixMultiply (benchmark::State& state) {
38+ static void BM_Matrix4Multiply (benchmark::State& state) {
3639 auto m1 = systems::leal::vector_math::Matrix4<float >::identity ();
3740 auto m2 = systems::leal::vector_math::Matrix4<float >(1 );
3841 for (auto _ : state){
3942 benchmark::DoNotOptimize (m1 * m2);
4043 }
4144}
42- BENCHMARK (BM_MatrixMultiply );
45+ BENCHMARK (BM_Matrix4Multiply );
4346
44- static void BM_MatrixByVector (benchmark::State& state) {
47+ static void BM_Matrix4ByVector (benchmark::State& state) {
4548 auto m1 = systems::leal::vector_math::Matrix4<float >::identity ();
4649 auto v1 = systems::leal::vector_math::Vector4<float >(1 ,2 ,3 ,4 );
4750 for (auto _ : state){
4851 benchmark::DoNotOptimize (m1 * v1);
4952 }
5053}
51- BENCHMARK (BM_MatrixByVector );
54+ BENCHMARK (BM_Matrix4ByVector );
5255
53- static void BM_LookAt (benchmark::State& state) {
56+ static void BM_Matrix4LookAt (benchmark::State& state) {
5457 auto eye = systems::leal::vector_math::Vector3<float >(0 ,0 ,0 );
5558 auto target = systems::leal::vector_math::Vector3<float >(0 ,0 ,1000 );
5659 auto up = systems::leal::vector_math::Vector3<float >(0 ,1 ,0 );
5760 for (auto _ : state){
5861 benchmark::DoNotOptimize (systems::leal::vector_math::Matrix4<float >::lookAt (eye, target, up));
5962 }
6063}
61- BENCHMARK (BM_LookAt);
64+ BENCHMARK (BM_Matrix4LookAt);
65+
66+ // //////////////////////
67+ // Matrix4f benchmark //
68+ // //////////////////////
69+ static void BM_Matrix4fCreation (benchmark::State& state) {
70+ for (auto _ : state){
71+ benchmark::DoNotOptimize (systems::leal::vector_math::Matrix4f ());
72+ }
73+ }
74+ BENCHMARK (BM_Matrix4fCreation);
75+
76+ static void BM_Matrix4fIdentity (benchmark::State& state) {
77+ for (auto _ : state){
78+ benchmark::DoNotOptimize (systems::leal::vector_math::Matrix4f::identity ());
79+ }
80+ }
81+ BENCHMARK (BM_Matrix4fIdentity);
82+
83+ static void BM_Matrix4fMultiply (benchmark::State& state) {
84+ systems::leal::vector_math::Matrix4f m1 = systems::leal::vector_math::Matrix4f::identity ();
85+ systems::leal::vector_math::Matrix4f m2 = systems::leal::vector_math::Matrix4f (1 );
86+ for (auto _ : state){
87+ benchmark::DoNotOptimize (m1 * m2);
88+ }
89+ }
90+ BENCHMARK (BM_Matrix4fMultiply);
91+
92+ static void BM_Matrix4fByVector (benchmark::State& state) {
93+ Matrix4f m1 = systems::leal::vector_math::Matrix4f::identity ();
94+ Vector4f v1 = systems::leal::vector_math::Vector4f (1 ,2 ,3 ,4 );
95+ for (auto _ : state){
96+ benchmark::DoNotOptimize (m1 * v1);
97+ }
98+ }
99+ BENCHMARK (BM_Matrix4fByVector);
100+
101+ static void BM_Matrix4fLookAt (benchmark::State& state) {
102+ auto eye = systems::leal::vector_math::Vector3<float >(0 ,0 ,0 );
103+ auto target = systems::leal::vector_math::Vector3<float >(0 ,0 ,1000 );
104+ auto up = systems::leal::vector_math::Vector3<float >(0 ,1 ,0 );
105+ for (auto _ : state){
106+ benchmark::DoNotOptimize (systems::leal::vector_math::Matrix4f::lookAt (eye, target, up));
107+ }
108+ }
109+ BENCHMARK (BM_Matrix4fLookAt);
62110
63111// /////////////////////////
64112// GLM Matrix4 benchmark //
0 commit comments