From 8da0d491a0b724dd737491a7144f19c5cc53ba8c Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 8 Oct 2023 05:07:39 +0200 Subject: aa --- test/dijkstra.cpp | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'test') diff --git a/test/dijkstra.cpp b/test/dijkstra.cpp index c19a7fcb..1db3ff22 100644 --- a/test/dijkstra.cpp +++ b/test/dijkstra.cpp @@ -1,26 +1,37 @@ #include "app.hpp" #include "path-search.hpp" #include +#include namespace floormat { -void test_app::test_dijkstra() -{ - auto w = world(); - auto a = astar(); +namespace { +template +requires requires (F& fun) { fun(); } +void bench_run(StringView name, F&& fun) +{ using namespace std::chrono; using clock = high_resolution_clock; - - const auto t0 = clock::now(); - + const auto t0 = clock::now(); + fun(); for (int i = 0; i < 10; i++) - { - a.Dijkstra(w, {}, 0, {{0, 0, 0}, {}}, {{1, 1, 0}, {}}, - 1*TILE_MAX_DIM*iTILE_SIZE2.x()); - } + fun(); const auto tm = clock::now() - t0; - Debug{} << "test took" << std::chrono::duration_cast(tm).count() << "ms."; + Debug{} << "test" << name << "took" << duration_cast(tm).count() << "ms."; +} + +} // namespace + +void test_app::test_dijkstra() +{ + auto w = world(); + auto a = astar(); + + bench_run("Dijkstra", [&] { + a.Dijkstra(w, {}, 0, {{0, 0, 0}, {}}, {{1, 1, 0}, {}}, + 1*TILE_MAX_DIM*iTILE_SIZE2.x()); + }); } } // namespace floormat -- cgit v1.2.3