tests: move benchmarks to new file, add clip benchmark

This commit is contained in:
Eric Wasylishen 2023-01-03 11:29:57 -07:00
parent a9a11159f4
commit c43371213e
4 changed files with 84 additions and 33 deletions

View File

@ -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})

82
tests/benchmark.cc Normal file
View File

@ -0,0 +1,82 @@
#include <nanobench.h>
#include <doctest/doctest.h>
#include <common/qvec.hh>
#include <common/polylib.hh>
#include <array>
#include <vector>
TEST_CASE("winding" * doctest::test_suite("benchmark")
* doctest::skip()) {
ankerl::nanobench::Bench bench;
bench.run("std::vector<double> reserve(3*4*6)", [&] {
std::vector<double> temp;
temp.reserve(3 * 4 * 6);
ankerl::nanobench::doNotOptimizeAway(temp);
});
bench.run("std::vector<qvec3d> reserve(4*6)", [&] {
std::vector<qvec3d> temp;
temp.reserve(4 * 6);
ankerl::nanobench::doNotOptimizeAway(temp);
});
bench.run("std::array<double, 3*4*6>", [&] {
std::array<double, 3 * 4 * 6> temp;
ankerl::nanobench::doNotOptimizeAway(temp);
});
bench.run("std::array<qvec3d, 4*6>", [&] {
std::array<qvec3d, 4 * 6> temp;
ankerl::nanobench::doNotOptimizeAway(temp);
});
bench.run("polylib::winding_base_t<6> construct", [&] {
polylib::winding_base_t<polylib::winding_storage_hybrid_t<6>> 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);
}

View File

@ -13,8 +13,6 @@
#include <common/log.hh>
#include <testmaps.hh>
#include <nanobench.h>
#include <fstream>
#include <cstring>
#include <stdexcept>
@ -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<double> reserve(3*4*6)", [&] {
std::vector<double> temp;
temp.reserve(3 * 4 * 6);
ankerl::nanobench::doNotOptimizeAway(temp);
});
bench.run("std::vector<qvec3d> reserve(4*6)", [&] {
std::vector<qvec3d> temp;
temp.reserve(4 * 6);
ankerl::nanobench::doNotOptimizeAway(temp);
});
bench.run("std::array<double, 3*4*6>", [&] {
std::array<double, 3 * 4 * 6> temp;
ankerl::nanobench::doNotOptimizeAway(temp);
});
bench.run("std::array<qvec3d, 4*6>", [&] {
std::array<qvec3d, 4 * 6> temp;
ankerl::nanobench::doNotOptimizeAway(temp);
});
bench.run("polylib::winding_base_t<6> construct", [&] {
polylib::winding_base_t<polylib::winding_storage_hybrid_t<6>> temp;
ankerl::nanobench::doNotOptimizeAway(temp);
});
}
TEST_CASE("BrushFromBounds") {
map.reset();
qbsp_options.reset();

View File

@ -2,8 +2,6 @@
#include <common/bsputils.hh>
#include <common/qvec.hh>
#include <nanobench.h>
#include <cstring>
#include <set>
#include <stdexcept>