diff options
author | Sven Göthel <[email protected]> | 2024-04-26 02:42:18 +0200 |
---|---|---|
committer | Sven Göthel <[email protected]> | 2024-04-26 02:42:18 +0200 |
commit | 38b762b41b1ab1ed014d3fd064f7ac25f2642fba (patch) | |
tree | 1b1882015fec5e905d362f2e580d918c48e2a66c /test/test_math_mat4f_02_mul.cpp | |
parent | 6153d3c827293027b88c440f312371313d2d8448 (diff) |
math: test_math_mat4f_02_mul: Enable 1s run only in `catch_perf_analysis` mode
Diffstat (limited to 'test/test_math_mat4f_02_mul.cpp')
-rw-r--r-- | test/test_math_mat4f_02_mul.cpp | 174 |
1 files changed, 174 insertions, 0 deletions
diff --git a/test/test_math_mat4f_02_mul.cpp b/test/test_math_mat4f_02_mul.cpp new file mode 100644 index 0000000..4122e30 --- /dev/null +++ b/test/test_math_mat4f_02_mul.cpp @@ -0,0 +1,174 @@ +/* + * Author: Sven Gothel <[email protected]> + * Copyright (c) 2024 Gothel Software e.K. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#include <thread> +#include <cinttypes> +#include <cstring> + +#include <jau/test/catch2_ext.hpp> + +#include <jau/int_math.hpp> +#include <jau/float_math.hpp> +#include <jau/math/vec2f.hpp> +#include <jau/math/vec2i.hpp> +#include <jau/math/vec3f.hpp> +#include <jau/math/vec4f.hpp> +#include <jau/math/mat4f.hpp> +#include <jau/math/quaternion.hpp> +#include <jau/math/aabbox2f.hpp> +#include <jau/math/aabbox3f.hpp> +#include <jau/math/mat4f.hpp> +#include <jau/math/recti.hpp> +#include <jau/math/math_error.hpp> + +using namespace jau; +using namespace jau::math; + +static const float m1_0[] = { 1, 3, 4, 0, + 6, 7, 8, 5, + 98, 7, 6, 9, + 54, 3, 2, 5 }; +static const Mat4f m1(m1_0); + +static const float m2_0[] = { 1, 6, 98, 54, + 3, 7, 7, 3, + 4, 8, 6, 2, + 0, 5, 9, 5 }; +static const Mat4f m2(m2_0); + +TEST_CASE( "Test 05 Perf01", "[mat4f][linear_algebra][math]" ) { + Mat4f res_m; + + const size_t warmups = 1000_u64; + const size_t loops = 300_u64*1000000_u64; + jau::fraction_i64 tI4a = fractions_i64::zero; + jau::fraction_i64 tI4b = fractions_i64::zero; + + const uint64_t tI5Max = 1000; // 1s + size_t loops5a = 0; + jau::fraction_i64 tI5a = fractions_i64::zero; + size_t loops5b = 0; + jau::fraction_i64 tI5b = fractions_i64::zero; + + // avoid optimizing out unused computation results by simply adding up determinat + double dr = 1; + + // + // Mat4f + // + + // warm-up + for(size_t i=0; i<warmups; i++) { + res_m = m1 * m2; + dr += res_m.determinant(); + res_m = m2 * m1; + dr += res_m.determinant(); + } + + jau::fraction_timespec t_0 = jau::getMonotonicTime(); + for(size_t i=0; i<loops; i++) { + res_m = m1 * m2; + dr += res_m.determinant(); + res_m = m2 * m1; + dr += res_m.determinant(); + } + tI4a = (getMonotonicTime() - t_0).to_fraction_i64(); + REQUIRE( dr > 0 ); + + // warm-up + for(size_t i=0; i<warmups; i++) { + res_m.load(m1); + res_m.mul(m2); + dr += res_m.determinant(); + res_m.load(m2); + res_m.mul(m1); + dr += res_m.determinant(); + } + + t_0 = jau::getMonotonicTime(); + for(size_t i=0; i<loops; i++) { + res_m.load(m1); + res_m.mul(m2); + dr += res_m.determinant(); + res_m.load(m2); + res_m.mul(m1); + dr += res_m.determinant(); + } + tI4b = (getMonotonicTime() - t_0).to_fraction_i64(); + REQUIRE( dr > 0 ); + + if( catch_perf_analysis ) { + tI5a = fractions_i64::zero; + t_0 = jau::getMonotonicTime(); + uint64_t t_5 = jau::getCurrentMilliseconds(); + uint64_t td_5=0; + while( td_5 < tI5Max ) { + res_m = m1 * m2; + dr += res_m.determinant(); + res_m = m2 * m1; + dr += res_m.determinant(); + ++loops5a; + // if( 0 == loops5a % 1000000 ) { + td_5 = jau::getCurrentMilliseconds() - t_5; + // } + } + tI5a = (getMonotonicTime() - t_0).to_fraction_i64(); + REQUIRE( dr > 0 ); + + tI5b = fractions_i64::zero; + t_0 = jau::getMonotonicTime(); + t_5 = jau::getCurrentMilliseconds(); + td_5=0; + while( td_5 < tI5Max ) { + res_m.load(m1); + res_m.mul(m2); + dr += res_m.determinant(); + res_m.load(m2); + res_m.mul(m1); + dr += res_m.determinant(); + ++loops5b; + // if( 0 == loops5b % 1000000 ) { + td_5 = jau::getCurrentMilliseconds() - t_5; + // } + } + tI5b = (getMonotonicTime() - t_0).to_fraction_i64(); + REQUIRE( dr > 0 ); + } + + printf("Checkmark %f\n", dr); + printf("Summary loops %6zu: I4a %6s ms total (%s us), %f ns/mul, I4a / I4b %f%%\n", loops, + jau::to_decstring(tI4a.to_ms()).c_str(), jau::to_decstring(tI4a.to_us()).c_str(), + (double)tI4a.to_ns()/2.0/(double)loops, tI4a.to_double()/tI4b.to_double()*100.0); + printf("Summary loops %6zu: I4b %6s ms total (%s us), %f ns/mul, I4b / I4a %f%%\n", loops, + jau::to_decstring(tI4b.to_ms()).c_str(), jau::to_decstring(tI4b.to_us()).c_str(), + (double)tI4b.to_ns()/2.0/(double)loops, tI4b.to_double()/tI4a.to_double()*100.0); + + if( catch_perf_analysis ) { + printf("Summary loops %6zu: I5a %6s ms total, %f ns/mul, I5a / I5b %f%%\n", loops5a, + jau::to_decstring(tI5a.to_ms()).c_str(), + (double)tI5a.to_ns()/2.0/(double)loops5a, tI5a.to_double()/tI5b.to_double()*100.0); + printf("Summary loops %6zu: I5b %6s ms total, %f ns/mul, I5b / I5a %f%%\n", loops5b, + jau::to_decstring(tI5b.to_ms()).c_str(), + (double)tI5b.to_ns()/2.0/(double)loops5b, tI5b.to_double()/tI5a.to_double()*100.0); + } +} |