From 5240a5c28a5225c4c1ebd02eb97c902e10d65657 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 6 Nov 2023 18:31:59 +0100 Subject: bbb --- bench/00-noop.cpp | 15 ----------- bench/01-dijkstra.cpp | 71 --------------------------------------------------- bench/02-loader.cpp | 36 -------------------------- bench/03-bitmask.cpp | 27 -------------------- bench/bitmask.cpp | 27 ++++++++++++++++++++ bench/dijkstra.cpp | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++ bench/loader.cpp | 36 ++++++++++++++++++++++++++ bench/noop.cpp | 15 +++++++++++ 8 files changed, 149 insertions(+), 149 deletions(-) delete mode 100644 bench/00-noop.cpp delete mode 100644 bench/01-dijkstra.cpp delete mode 100644 bench/02-loader.cpp delete mode 100644 bench/03-bitmask.cpp create mode 100644 bench/bitmask.cpp create mode 100644 bench/dijkstra.cpp create mode 100644 bench/loader.cpp create mode 100644 bench/noop.cpp diff --git a/bench/00-noop.cpp b/bench/00-noop.cpp deleted file mode 100644 index ca84944a..00000000 --- a/bench/00-noop.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include - -#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 deleted file mode 100644 index 08f310d4..00000000 --- a/bench/01-dijkstra.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include "src/path-search.hpp" -#include "src/path-search-result.hpp" -#include "loader/loader.hpp" -#include -#include -#include - -namespace floormat { - -namespace { - -auto A = astar(); -bool first_run = false; - - -void Dijkstra(benchmark::State& state) -{ - auto w = world(); - - constexpr auto wcx = 1, wcy = 1, wtx = 8, wty = 8, wox = 0, woy = 0; - 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[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 : { 3, 4, 5, 6, 11, 12, 13, 14, 15, }) - { - c[{ k, k }].wall_north() = metal2; - c[{ k, k }].wall_west() = metal2; - } - } - - ch[{ wtx, wty }].wall_west() = metal2; - ch[{ wtx, wty }].wall_north() = metal2; - ch[{ wtx+1, wty }].wall_west() = metal2; - ch[{ wtx, wty +1}].wall_north() = metal2; - - 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}]; - c.mark_passability_modified(); - c.ensure_passability(); - } - - auto run = [&] { - A.Dijkstra(w, - {{0,0,0}, {11,9}}, // from - {wpos, {wox, woy}}, // to - 0, max_dist, {16,16}, // size - first_run ? 1 : 0); - }; - - run(); - first_run = false; - for (auto _ : state) - run(); -} - -} // namespace - -BENCHMARK(Dijkstra)->Unit(benchmark::kMillisecond)->ReportAggregatesOnly(); - -} // namespace floormat diff --git a/bench/02-loader.cpp b/bench/02-loader.cpp deleted file mode 100644 index d4d22520..00000000 --- a/bench/02-loader.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "loader/loader.hpp" -#include "serialize/json-helper.hpp" -#include "serialize/anim.hpp" -#include -#include -#include -#include - -namespace floormat { - -namespace { - -void Loader_json(benchmark::State& state) -{ - loader.destroy(); - - // warmup - { for (const auto& x : loader.anim_atlas_list()) - json_helper::from_json(Path::join(loader.ANIM_PATH, ""_s.join({x, ".json"}))); - json_helper::from_json>(Path::join(loader.VOBJ_PATH, "vobj.json")); - } - - for (auto _ : state) - for (int i = 0; i < 10; i++) - { - for (const auto& x : loader.anim_atlas_list()) - json_helper::from_json(Path::join(loader.ANIM_PATH, ""_s.join({x, ".json"}))); - json_helper::from_json>(Path::join(loader.VOBJ_PATH, "vobj.json")); - } -} - -BENCHMARK(Loader_json)->Unit(benchmark::kMillisecond)->ReportAggregatesOnly(); - -} // namespace - -} // namespace floormat diff --git a/bench/03-bitmask.cpp b/bench/03-bitmask.cpp deleted file mode 100644 index c8c698a6..00000000 --- a/bench/03-bitmask.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "compat/assert.hpp" -#include "src/anim-atlas.hpp" -#include "loader/loader.hpp" -#include -#include -#include -#include - -namespace floormat { - -namespace { - -[[maybe_unused]] void Bitmask(benchmark::State& state) -{ - auto img = loader.texture(loader.SCENERY_PATH, "door-close"_s); - auto bitmask = anim_atlas::make_bitmask(img); - anim_atlas::make_bitmask_(img, bitmask); - - for (auto _ : state) - anim_atlas::make_bitmask_(img, bitmask); -} - -BENCHMARK(Bitmask)->Unit(benchmark::kMicrosecond)->ReportAggregatesOnly(); - -} // namespace - -} // namespace floormat diff --git a/bench/bitmask.cpp b/bench/bitmask.cpp new file mode 100644 index 00000000..c8c698a6 --- /dev/null +++ b/bench/bitmask.cpp @@ -0,0 +1,27 @@ +#include "compat/assert.hpp" +#include "src/anim-atlas.hpp" +#include "loader/loader.hpp" +#include +#include +#include +#include + +namespace floormat { + +namespace { + +[[maybe_unused]] void Bitmask(benchmark::State& state) +{ + auto img = loader.texture(loader.SCENERY_PATH, "door-close"_s); + auto bitmask = anim_atlas::make_bitmask(img); + anim_atlas::make_bitmask_(img, bitmask); + + for (auto _ : state) + anim_atlas::make_bitmask_(img, bitmask); +} + +BENCHMARK(Bitmask)->Unit(benchmark::kMicrosecond)->ReportAggregatesOnly(); + +} // namespace + +} // namespace floormat diff --git a/bench/dijkstra.cpp b/bench/dijkstra.cpp new file mode 100644 index 00000000..08f310d4 --- /dev/null +++ b/bench/dijkstra.cpp @@ -0,0 +1,71 @@ +#include "src/path-search.hpp" +#include "src/path-search-result.hpp" +#include "loader/loader.hpp" +#include +#include +#include + +namespace floormat { + +namespace { + +auto A = astar(); +bool first_run = false; + + +void Dijkstra(benchmark::State& state) +{ + auto w = world(); + + constexpr auto wcx = 1, wcy = 1, wtx = 8, wty = 8, wox = 0, woy = 0; + 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[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 : { 3, 4, 5, 6, 11, 12, 13, 14, 15, }) + { + c[{ k, k }].wall_north() = metal2; + c[{ k, k }].wall_west() = metal2; + } + } + + ch[{ wtx, wty }].wall_west() = metal2; + ch[{ wtx, wty }].wall_north() = metal2; + ch[{ wtx+1, wty }].wall_west() = metal2; + ch[{ wtx, wty +1}].wall_north() = metal2; + + 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}]; + c.mark_passability_modified(); + c.ensure_passability(); + } + + auto run = [&] { + A.Dijkstra(w, + {{0,0,0}, {11,9}}, // from + {wpos, {wox, woy}}, // to + 0, max_dist, {16,16}, // size + first_run ? 1 : 0); + }; + + run(); + first_run = false; + for (auto _ : state) + run(); +} + +} // namespace + +BENCHMARK(Dijkstra)->Unit(benchmark::kMillisecond)->ReportAggregatesOnly(); + +} // namespace floormat diff --git a/bench/loader.cpp b/bench/loader.cpp new file mode 100644 index 00000000..d4d22520 --- /dev/null +++ b/bench/loader.cpp @@ -0,0 +1,36 @@ +#include "loader/loader.hpp" +#include "serialize/json-helper.hpp" +#include "serialize/anim.hpp" +#include +#include +#include +#include + +namespace floormat { + +namespace { + +void Loader_json(benchmark::State& state) +{ + loader.destroy(); + + // warmup + { for (const auto& x : loader.anim_atlas_list()) + json_helper::from_json(Path::join(loader.ANIM_PATH, ""_s.join({x, ".json"}))); + json_helper::from_json>(Path::join(loader.VOBJ_PATH, "vobj.json")); + } + + for (auto _ : state) + for (int i = 0; i < 10; i++) + { + for (const auto& x : loader.anim_atlas_list()) + json_helper::from_json(Path::join(loader.ANIM_PATH, ""_s.join({x, ".json"}))); + json_helper::from_json>(Path::join(loader.VOBJ_PATH, "vobj.json")); + } +} + +BENCHMARK(Loader_json)->Unit(benchmark::kMillisecond)->ReportAggregatesOnly(); + +} // namespace + +} // namespace floormat diff --git a/bench/noop.cpp b/bench/noop.cpp new file mode 100644 index 00000000..ca84944a --- /dev/null +++ b/bench/noop.cpp @@ -0,0 +1,15 @@ +#include + +#if 0 +namespace { + +void noop(benchmark::State& state) +{ + for (auto _ : state) + (void)0; +} + +BENCHMARK(noop); + +} // namespace +#endif -- cgit v1.2.3