From c43371213ee6fa5c4255c25fed3d39b063a6edbc Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Tue, 3 Jan 2023 11:29:57 -0700 Subject: [PATCH] tests: move benchmarks to new file, add clip benchmark --- tests/CMakeLists.txt | 3 +- tests/benchmark.cc | 82 +++++++++++++++++++++++++++++++++++++++++++ tests/test_qbsp.cc | 30 ---------------- tests/test_qbsp_q2.cc | 2 -- 4 files changed, 84 insertions(+), 33 deletions(-) create mode 100644 tests/benchmark.cc diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 14c453da..cfad0f67 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -13,7 +13,8 @@ add_executable(tests test_vis.cc testutils.hh ${CMAKE_BINARY_DIR}/testmaps.hh - testutils.hh) + testutils.hh + benchmark.cc) find_package(embree 3.0 REQUIRED) INCLUDE_DIRECTORIES(${EMBREE_INCLUDE_DIRS}) diff --git a/tests/benchmark.cc b/tests/benchmark.cc new file mode 100644 index 00000000..23b19b8f --- /dev/null +++ b/tests/benchmark.cc @@ -0,0 +1,82 @@ +#include +#include +#include +#include + +#include +#include + +TEST_CASE("winding" * doctest::test_suite("benchmark") + * doctest::skip()) { + ankerl::nanobench::Bench bench; + + bench.run("std::vector reserve(3*4*6)", [&] { + std::vector temp; + temp.reserve(3 * 4 * 6); + ankerl::nanobench::doNotOptimizeAway(temp); + }); + bench.run("std::vector reserve(4*6)", [&] { + std::vector temp; + temp.reserve(4 * 6); + ankerl::nanobench::doNotOptimizeAway(temp); + }); + bench.run("std::array", [&] { + std::array temp; + ankerl::nanobench::doNotOptimizeAway(temp); + }); + bench.run("std::array", [&] { + std::array temp; + ankerl::nanobench::doNotOptimizeAway(temp); + }); + bench.run("polylib::winding_base_t<6> construct", [&] { + polylib::winding_base_t> temp; + ankerl::nanobench::doNotOptimizeAway(temp); + }); +} + +static void test_polylib(bool check_results) +{ + polylib::winding_t w(4); + + // top face to TB default brush + w[0] = {-64, 64, 16}; + w[1] = { 64, 64, 16}; + w[2] = { 64, -64, 16}; + w[3] = {-64, -64, 16}; + + qplane3d splitplane{{1, 0, 0}, 0}; + auto [front, back] = w.clip(splitplane); + + ankerl::nanobench::doNotOptimizeAway(front); + ankerl::nanobench::doNotOptimizeAway(back); + + if (check_results) { + REQUIRE(front); + REQUIRE(back); + + CHECK(front->size() == 4); + CHECK(back->size() == 4); + + // check front polygon + CHECK(front->at(0) == qvec3d{0, 64, 16}); + CHECK(front->at(1) == qvec3d{64, 64, 16}); + CHECK(front->at(2) == qvec3d{64, -64, 16}); + CHECK(front->at(3) == qvec3d{0, -64, 16}); + + // check back polygon + CHECK(back->at(0) == qvec3d{-64, 64, 16}); + CHECK(back->at(1) == qvec3d{0, 64, 16}); + CHECK(back->at(2) == qvec3d{0, -64, 16}); + CHECK(back->at(3) == qvec3d{-64, -64, 16}); + } +} + +TEST_CASE("SplitFace" * doctest::test_suite("benchmark")) +{ + ankerl::nanobench::Bench().run("create and split a face (polylib)", [&]() { + test_polylib(false); + }); + + // run with doctest assertions, to validate that they actually work + test_polylib(true); +} diff --git a/tests/test_qbsp.cc b/tests/test_qbsp.cc index 0ebc0893..859f617e 100644 --- a/tests/test_qbsp.cc +++ b/tests/test_qbsp.cc @@ -13,8 +13,6 @@ #include #include -#include - #include #include #include @@ -1590,34 +1588,6 @@ TEST_CASE("q1_hull1_content_types" * doctest::test_suite("testmaps_q1")) } } -TEST_CASE("winding" * doctest::test_suite("benchmark") - * doctest::skip()) { - ankerl::nanobench::Bench bench; - - bench.run("std::vector reserve(3*4*6)", [&] { - std::vector temp; - temp.reserve(3 * 4 * 6); - ankerl::nanobench::doNotOptimizeAway(temp); - }); - bench.run("std::vector reserve(4*6)", [&] { - std::vector temp; - temp.reserve(4 * 6); - ankerl::nanobench::doNotOptimizeAway(temp); - }); - bench.run("std::array", [&] { - std::array temp; - ankerl::nanobench::doNotOptimizeAway(temp); - }); - bench.run("std::array", [&] { - std::array temp; - ankerl::nanobench::doNotOptimizeAway(temp); - }); - bench.run("polylib::winding_base_t<6> construct", [&] { - polylib::winding_base_t> temp; - ankerl::nanobench::doNotOptimizeAway(temp); - }); -} - TEST_CASE("BrushFromBounds") { map.reset(); qbsp_options.reset(); diff --git a/tests/test_qbsp_q2.cc b/tests/test_qbsp_q2.cc index 69c55ec9..ebff24c8 100644 --- a/tests/test_qbsp_q2.cc +++ b/tests/test_qbsp_q2.cc @@ -2,8 +2,6 @@ #include #include -#include - #include #include #include