summaryrefslogtreecommitdiffhomepage
path: root/bench
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-10-11 10:35:06 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-10-11 13:35:27 +0200
commitca4544f04cc67c296e58170e76203bc11519d988 (patch)
tree2dcbe936be206c4e7f95a28525fafff6f7340e5e /bench
parent018755dab3d2a5bb0ead627b6ecad6735a9f0114 (diff)
add benchmark executable
Diffstat (limited to 'bench')
-rw-r--r--bench/00-noop.cpp15
-rw-r--r--bench/01-dijkstra.cpp67
-rw-r--r--bench/CMakeLists.txt24
-rw-r--r--bench/dummy.cc0
-rw-r--r--bench/main.cpp57
5 files changed, 163 insertions, 0 deletions
diff --git a/bench/00-noop.cpp b/bench/00-noop.cpp
new file mode 100644
index 00000000..ca84944a
--- /dev/null
+++ b/bench/00-noop.cpp
@@ -0,0 +1,15 @@
+#include <benchmark/benchmark.h>
+
+#if 0
+namespace {
+
+void noop(benchmark::State& state)
+{
+ for (auto _ : state)
+ (void)0;
+}
+
+BENCHMARK(noop);
+
+} // namespace
+#endif
diff --git a/bench/01-dijkstra.cpp b/bench/01-dijkstra.cpp
new file mode 100644
index 00000000..b358f1f9
--- /dev/null
+++ b/bench/01-dijkstra.cpp
@@ -0,0 +1,67 @@
+#include "src/path-search.hpp"
+#include "src/path-search-result.hpp"
+#include "loader/loader.hpp"
+#include <benchmark/benchmark.h>
+#include <Corrade/Containers/Optional.h>
+#include <Magnum/Math/Functions.h>
+
+namespace floormat {
+
+namespace {
+
+auto A = astar();
+bool first_run = true;
+
+void Dijkstra(benchmark::State& state)
+{
+ auto w = world();
+
+ 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}];
+ auto& ch2 = w[wch];
+ auto metal2 = tile_image_proto{loader.tile_atlas("metal2", {2, 2}, pass_mode::blocked), 0};
+
+ for (int16_t j = wcy - 1; j <= wcy + 1; j++)
+ for (int16_t i = wcx - 1; i <= wcx + 1; i++)
+ {
+ auto &c = w[chunk_coords_{i, j, 0}];
+ for (int k : { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, })
+ {
+ c[{ k, k }].wall_north() = metal2;
+ c[{ k, k }].wall_west() = 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;
+
+ fm_assert(ch.is_passability_modified());
+ ch.ensure_passability();
+ ch2.ensure_passability();
+
+ auto run = [&] {
+ A.Dijkstra(w,
+ {{0,0,0}, {11,9}}, // from
+ {wpos, {wox, woy}}, // to
+ 0, max_dist, {32,32}, // size
+ first_run ? 1 : 0);
+ };
+
+ run();
+ first_run = false;
+ for (auto _ : state)
+ run();
+}
+
+} // namespace
+
+BENCHMARK(Dijkstra);
+
+} // namespace floormat
diff --git a/bench/CMakeLists.txt b/bench/CMakeLists.txt
new file mode 100644
index 00000000..ecce9dee
--- /dev/null
+++ b/bench/CMakeLists.txt
@@ -0,0 +1,24 @@
+set(self floormat-benchmark)
+
+file(GLOB sources "*.cpp" CONFIGURE_ARGS)
+
+add_library(${self}_o OBJECT "${res}" "${sources}")
+add_executable(${self} dummy.cc)
+
+target_link_libraries(${self}_o PUBLIC
+ ${floormat_headless-library}
+ Magnum::Magnum
+ Magnum::Trade
+ nlohmann_json::nlohmann_json
+ fmt::fmt
+ tsl::robin_map
+)
+
+if(TARGET benchmark::benchmark)
+ target_link_libraries(${self}_o PUBLIC benchmark::benchmark)
+else()
+ target_link_libraries(${self}_o PUBLIC benchmark)
+endif()
+
+target_link_libraries(${self} PUBLIC ${self}_o floormat-serialize floormat-draw floormat)
+install(TARGETS ${self} RUNTIME DESTINATION bin)
diff --git a/bench/dummy.cc b/bench/dummy.cc
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/bench/dummy.cc
diff --git a/bench/main.cpp b/bench/main.cpp
new file mode 100644
index 00000000..80a491ec
--- /dev/null
+++ b/bench/main.cpp
@@ -0,0 +1,57 @@
+#include "loader/loader.hpp"
+#include "compat/headless.hpp"
+#include <benchmark/benchmark.h>
+
+namespace floormat {
+
+namespace {
+
+#define main bench_main
+int bench_main(int argc, char** argv);
+BENCHMARK_MAIN();
+#undef main
+
+struct bench_app final : private FM_APPLICATION
+{
+ using Application = FM_APPLICATION;
+ explicit bench_app(int argc, char** argv);
+
+ int exec() override;
+ ~bench_app();
+
+ int argc;
+ char** argv;
+};
+bench_app::~bench_app() { loader_::destroy(); }
+
+int argc_ = 0; // NOLINT
+
+bench_app::bench_app(int argc, char** argv) :
+ Application {
+ {argc_, nullptr},
+ Configuration{}
+ },
+ argc{argc}, argv{argv}
+{
+}
+
+int bench_app::exec()
+{
+ return bench_main(argc, argv);
+}
+
+} // namespace
+
+} // namespace floormat
+
+using namespace floormat;
+
+int main(int argc, char** argv)
+{
+ int status;
+ { auto app = bench_app{argc, argv};
+ status = app.exec();
+ }
+ loader_::destroy();
+ return status;
+}