From 7ba2c87b128fbbb376e17494e3cc41d6e6e87674 Mon Sep 17 00:00:00 2001 From: waqar-ukaea Date: Mon, 24 Feb 2025 16:23:55 +0000 Subject: [PATCH 1/4] Started adding micro-benchmarks with Catch2 --- tests/test_ray_fire.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/test_ray_fire.cpp b/tests/test_ray_fire.cpp index b87e9f2a..0e005b41 100644 --- a/tests/test_ray_fire.cpp +++ b/tests/test_ray_fire.cpp @@ -2,6 +2,7 @@ // for testing #include #include +#include // xdg includes #include "xdg/constants.h" @@ -29,6 +30,10 @@ TEST_CASE("Test Ray Fire Mesh Mock") intersection = rti->ray_fire(volume_tree, origin, direction); REQUIRE_THAT(intersection.first, Catch::Matchers::WithinAbs(5.0, 1e-6)); + BENCHMARK("ray_fire_1"){ + return rti->ray_fire(volume_tree, origin, direction); + }; + direction *= -1; intersection = rti->ray_fire(volume_tree, origin, direction); REQUIRE_THAT(intersection.first, Catch::Matchers::WithinAbs(2.0, 1e-6)); @@ -98,3 +103,18 @@ TEST_CASE("Test Ray Fire Mesh Mock") intersection = rti->ray_fire(volume_tree, origin, direction, INFTY, HitOrientation::EXITING, &exclude_primitives); REQUIRE(intersection.second == ID_NONE); } + + +// TEST_CASE("Micro-Benchmark ray_fire()") +// { +// std::shared_ptr mm = std::make_shared(); +// mm->init(); // this should do nothing, just good practice to call it +// REQUIRE(mm->mesh_library() == MeshLibrary::INTERNAL); + +// std::shared_ptr rti = std::make_shared(); +// TreeID volume_tree = rti->register_volume(mm, mm->volumes()[0]); + +// Position origin {0.0, 0.0, 0.0}; +// Direction direction {1.0, 0.0, 0.0}; +// std::pair intersection; +// } \ No newline at end of file From 676e2285aec3517d4f634d6cf637a0b650fc0ae4 Mon Sep 17 00:00:00 2001 From: waqar-ukaea Date: Tue, 25 Feb 2025 11:34:30 +0000 Subject: [PATCH 2/4] Added some simple catch2 benchmarks to existing ray_fire and point_in_vol tests --- .github/workflows/ci.yml | 2 +- tests/test_point_in_volume.cpp | 10 ++++++++++ tests/test_ray_fire.cpp | 11 ++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 33ed001b..cb7975af 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,7 +71,7 @@ jobs: shell: bash run: | cd build - ctest -j4 --output-on-failure + ctest -j4 --output-on-failure --verbose - name: Check installed executables shell: bash diff --git a/tests/test_point_in_volume.cpp b/tests/test_point_in_volume.cpp index 57a5b2d2..048e90e8 100644 --- a/tests/test_point_in_volume.cpp +++ b/tests/test_point_in_volume.cpp @@ -4,6 +4,8 @@ // xdg includes #include "xdg/mesh_manager_interface.h" #include "xdg/ray_tracing_interface.h" +#include + #include "mesh_mock.h" @@ -22,10 +24,18 @@ TEST_CASE("Test Point in Volume") bool result = rti->point_in_volume(volume_tree, point); REQUIRE(result == true); + BENCHMARK("point_in_vol [Inside]"){ + return rti->point_in_volume(volume_tree, point); + }; + point = {0.0, 0.0, 1000.0}; result = rti->point_in_volume(volume_tree, point); REQUIRE(result == false); + BENCHMARK("point_in_vol [Outside]"){ + return rti->point_in_volume(volume_tree, point); + }; + // test a point just inside the positive x boundary point = {4.0 - 1e-06, 0.0, 0.0}; result = rti->point_in_volume(volume_tree, point); diff --git a/tests/test_ray_fire.cpp b/tests/test_ray_fire.cpp index 0e005b41..32e1c909 100644 --- a/tests/test_ray_fire.cpp +++ b/tests/test_ray_fire.cpp @@ -30,7 +30,8 @@ TEST_CASE("Test Ray Fire Mesh Mock") intersection = rti->ray_fire(volume_tree, origin, direction); REQUIRE_THAT(intersection.first, Catch::Matchers::WithinAbs(5.0, 1e-6)); - BENCHMARK("ray_fire_1"){ + // benchmark firing from inside the cube to a face + BENCHMARK("ray_fire_from_inside"){ return rti->ray_fire(volume_tree, origin, direction); }; @@ -61,6 +62,10 @@ TEST_CASE("Test Ray Fire Mesh Mock") intersection = rti->ray_fire(volume_tree, origin, direction); REQUIRE_THAT(intersection.first, Catch::Matchers::WithinAbs(15.0, 1e-6)); + BENCHMARK("ray_fire_from_outside_vol [Exiting]"){ + return rti->ray_fire(volume_tree, origin, direction); + }; + origin = {10.0, 0.0, 0.0}; direction = {-1.0, 0.0, 0.0}; intersection = rti->ray_fire(volume_tree, origin, direction); @@ -73,6 +78,10 @@ TEST_CASE("Test Ray Fire Mesh Mock") intersection = rti->ray_fire(volume_tree, origin, direction, INFTY, HitOrientation::ENTERING); REQUIRE_THAT(intersection.first, Catch::Matchers::WithinAbs(8.0, 1e-6)); + BENCHMARK("ray_fire_from_outside_vol [Entering]"){ + return rti->ray_fire(volume_tree, origin, direction); + }; + origin = {10.0, 0.0, 0.0}; direction = {-1.0, 0.0, 0.0}; intersection = rti->ray_fire(volume_tree, origin, direction, INFTY, HitOrientation::ENTERING); From e176918cf709a4d7ed01029b7cfc20ca9e9eccc5 Mon Sep 17 00:00:00 2001 From: Waqar Butt <114666466+Waqar-ukaea@users.noreply.github.com> Date: Tue, 25 Feb 2025 11:48:02 +0000 Subject: [PATCH 3/4] Update ci.yml to run tests in serial --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cb7975af..962fe68e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,7 +71,7 @@ jobs: shell: bash run: | cd build - ctest -j4 --output-on-failure --verbose + ctest -j1 --output-on-failure --verbose - name: Check installed executables shell: bash From 38ababd11471ce84a6cf6bbb69e5c4a51c0260b1 Mon Sep 17 00:00:00 2001 From: waqar-ukaea Date: Wed, 5 Mar 2025 09:17:37 +0000 Subject: [PATCH 4/4] trying out a Catch2::ADVANCED_BENCHMARK --- tests/test_ray_fire.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_ray_fire.cpp b/tests/test_ray_fire.cpp index 32e1c909..6b5bd572 100644 --- a/tests/test_ray_fire.cpp +++ b/tests/test_ray_fire.cpp @@ -35,6 +35,13 @@ TEST_CASE("Test Ray Fire Mesh Mock") return rti->ray_fire(volume_tree, origin, direction); }; + // advanced benchmark + BENCHMARK_ADVANCED("Advanced ray_fire benchmark")(Catch::Benchmark::Chronometer meter){ + meter.measure([]{ + return rti->ray_fire(volume_tree, origin, direction); + }); + }; + direction *= -1; intersection = rti->ray_fire(volume_tree, origin, direction); REQUIRE_THAT(intersection.first, Catch::Matchers::WithinAbs(2.0, 1e-6));