From ca4544f04cc67c296e58170e76203bc11519d988 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 11 Oct 2023 10:35:06 +0200 Subject: add benchmark executable --- test/CMakeLists.txt | 15 ++++++-------- test/app.cpp | 58 ----------------------------------------------------- test/app.hpp | 13 +----------- test/dijkstra.cpp | 56 --------------------------------------------------- test/main.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 62 insertions(+), 135 deletions(-) delete mode 100644 test/app.cpp create mode 100644 test/main.cpp (limited to 'test') diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0d713de5..f8048278 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -4,15 +4,12 @@ file(GLOB sources "*.cpp" CONFIGURE_ARGS) file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/test") add_library(${self}_o OBJECT "${sources}") -target_link_libraries(${self}_o PUBLIC Magnum::GL Magnum::Trade nlohmann_json::nlohmann_json fmt::fmt tsl::robin_map) - -if(APPLE) - target_link_libraries(${self}_o PUBLIC Magnum::WindowlessCglApplication) -elseif(WIN32) - target_link_libraries(${self}_o PUBLIC Magnum::WindowlessWglApplication ntdll) -else() - target_link_libraries(${self}_o PUBLIC Magnum::WindowlessGlxApplication) -endif() +target_link_libraries(${self}_o PUBLIC + ${floormat_headless-library} + Magnum::GL Magnum::Trade + nlohmann_json::nlohmann_json + fmt::fmt tsl::robin_map +) add_executable(${self} dummy.cc) target_link_libraries(${self} ${self}_o floormat-serialize floormat) diff --git a/test/app.cpp b/test/app.cpp deleted file mode 100644 index 3e1f7f82..00000000 --- a/test/app.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "app.hpp" -#include "compat/assert.hpp" -#include "loader/loader.hpp" -#include -#include - -namespace floormat { - -test_app::test_app(const Arguments& arguments): - Application { - arguments, - Configuration{} - } -{ -} - -test_app::~test_app() -{ - loader_::destroy(); -} - -int test_app::exec() -{ - test_coords(); - test_json(); - test_tile_iter(); - test_magnum_math(); - test_entity(); - test_loader(); - test_bitmask(); - test_serializer_1(); - test_serializer_2(); - test_path_search(); - test_math(); - test_hash(); - test_path_search_node_pool(); - - test_dijkstra(); - - zzz_test_misc(); - - return 0; -} - -} // namespace floormat - -int main(int argc, char** argv) -{ -#ifdef _WIN32 - // NOLINTNEXTLINE(concurrency-mt-unsafe) - if (const auto* s = std::getenv("MAGNUM_LOG"); !s || !*s) - _putenv("MAGNUM_LOG=quiet"); -#else - setenv("MAGNUM_LOG", "quiet", 0); -#endif - floormat::test_app application{{argc, argv}}; - return application.exec(); -} diff --git a/test/app.hpp b/test/app.hpp index 0822e68f..630acf02 100644 --- a/test/app.hpp +++ b/test/app.hpp @@ -1,19 +1,9 @@ #pragma once #undef FM_NO_DEBUG #include "compat/assert.hpp" +#include "compat/headless.hpp" #include -#ifdef __APPLE__ -#include -#define FM_APPLICATION Platform::WindowlessCglApplication -#elif defined _WIN32 -#include -#define FM_APPLICATION Platform::WindowlessWglApplication -#else -#include -#define FM_APPLICATION Platform::WindowlessGlxApplication -#endif - namespace floormat { struct chunk_coords; @@ -44,7 +34,6 @@ struct test_app final : private FM_APPLICATION static void test_path_search(); static void test_hash(); static void test_path_search_node_pool(); - static void test_dijkstra(); static void zzz_test_misc(); }; } // namespace floormat diff --git a/test/dijkstra.cpp b/test/dijkstra.cpp index 301257b1..e69de29b 100644 --- a/test/dijkstra.cpp +++ b/test/dijkstra.cpp @@ -1,56 +0,0 @@ -#include "app.hpp" -#include "bench.hpp" -#include "src/path-search.hpp" -#include "loader/loader.hpp" -#include - -namespace floormat { - -void test_app::test_dijkstra() -{ - auto w = world(); - auto a = astar(); - - constexpr auto wcx = 1, wcy = 1, wtx = 8, wty = 8, wox = 3, woy = 3; - constexpr auto max_dist = (uint32_t)(Vector2i(Math::abs(wcx)+1, Math::abs(wcy)+1)*TILE_MAX_DIM*iTILE_SIZE2).length(); - constexpr auto wch = chunk_coords_{wcx, wcy, 0}; - constexpr auto wt = local_coords{wtx, wty}; - constexpr auto wpos = global_coords{wch, wt}; - - auto& ch = w[chunk_coords_{0,0,0}]; -#if 1 - auto& ch2 = w[wch]; - auto metal2 = tile_image_proto{loader.tile_atlas("metal2", {2, 2}, pass_mode::blocked), 0}; - - ch[{4, 4}].wall_west() = metal2; - ch[{4, 4}].wall_north() = metal2; - - ch2[{ wtx, wty }].wall_west() = metal2; - ch2[{ wtx, wty }].wall_north() = metal2; - ch2[{ wtx+1, wty }].wall_west() = metal2; - ch2[{ wtx, wty -1}].wall_north() = metal2; -#endif - - fm_assert(ch.is_passability_modified()); - - auto do_bench = [&](int count, int debug) { - for (int i = 0; i < count; i++) - a.Dijkstra(w, - {{0,0,0}, {11,9}}, // from - {wpos, {wox, woy}}, // to - 0, max_dist, {32,32}, // size - debug); - }; - - static constexpr int iters = 10; - if constexpr (iters > 1) - do_bench(1, 1); -#if 1 - for (int i = 0; i < iters; i++) - bench_run("Dijkstra", [&] { - do_bench(1, iters == 1); - }); -#endif -} - -} // namespace floormat diff --git a/test/main.cpp b/test/main.cpp new file mode 100644 index 00000000..c6ef7557 --- /dev/null +++ b/test/main.cpp @@ -0,0 +1,55 @@ +#include "app.hpp" +#include "compat/assert.hpp" +#include "loader/loader.hpp" +#include +#include + +namespace floormat { + +test_app::test_app(const Arguments& arguments): + Application { + arguments, + Configuration{} + } +{ +} + +test_app::~test_app() +{ + loader_::destroy(); +} + +int test_app::exec() +{ + test_coords(); + test_json(); + test_tile_iter(); + test_magnum_math(); + test_entity(); + test_loader(); + test_bitmask(); + test_serializer_1(); + test_serializer_2(); + test_path_search(); + test_math(); + test_hash(); + test_path_search_node_pool(); + zzz_test_misc(); + + return 0; +} + +} // namespace floormat + +int main(int argc, char** argv) +{ +#ifdef _WIN32 + // NOLINTNEXTLINE(concurrency-mt-unsafe) + if (const auto* s = std::getenv("MAGNUM_LOG"); !s || !*s) + _putenv("MAGNUM_LOG=quiet"); +#else + setenv("MAGNUM_LOG", "quiet", 0); +#endif + floormat::test_app application{{argc, argv}}; + return application.exec(); +} -- cgit v1.2.3