summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-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