summaryrefslogtreecommitdiffhomepage
path: root/test/dijkstra.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-10-08 05:07:39 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-10-08 05:08:50 +0200
commit8da0d491a0b724dd737491a7144f19c5cc53ba8c (patch)
tree0059915c246adecdb2b1cef5310693f79fc28bbf /test/dijkstra.cpp
parent5a1dacd18838536fd1934a3388e0364e5a53bee3 (diff)
aa
Diffstat (limited to 'test/dijkstra.cpp')
-rw-r--r--test/dijkstra.cpp35
1 files changed, 23 insertions, 12 deletions
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 <chrono>
+#include <Corrade/Containers/StringView.h>
namespace floormat {
-void test_app::test_dijkstra()
-{
- auto w = world();
- auto a = astar();
+namespace {
+template<typename F>
+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<milliseconds>(tm).count() << "ms.";
+ Debug{} << "test" << name << "took" << duration_cast<milliseconds>(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