From 3a4fb937342c5bc57fce0f48b81b81ed06b32bf9 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 28 Feb 2024 23:46:23 +0100 Subject: editor/tests: show timing info in the ui --- editor/tests/raycast-test.cpp | 10 ++++++++++ editor/tests/region-test.cpp | 9 +++++++++ 2 files changed, 19 insertions(+) (limited to 'editor/tests') diff --git a/editor/tests/raycast-test.cpp b/editor/tests/raycast-test.cpp index 1b06c0f3..76fdde8b 100644 --- a/editor/tests/raycast-test.cpp +++ b/editor/tests/raycast-test.cpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace floormat::tests { @@ -56,6 +57,7 @@ struct raycast_test final : base_test raycast_result_s result; pending_s pending; raycast_diag_s diag; + float time = 0; ~raycast_test() noexcept override; @@ -68,6 +70,7 @@ struct raycast_test final : base_test { if (e.button == mouse_button_left && is_down) { + time = 0; auto& M = a.main(); auto& w = M.world(); if (auto pt_ = a.cursor_state().point()) @@ -245,6 +248,10 @@ struct raycast_test final : base_test do_column("path-len"); std::snprintf(buf, std::size(buf), "%zu", diag.path.size()); text(buf); + + do_column("time"); + std::snprintf(buf, std::size(buf), "%.3f ms", (double)(1000 * time)); + text(buf); } } @@ -263,7 +270,10 @@ struct raycast_test final : base_test fm_warn("raycast: wrong Z value"); return; } + Timeline timeline; + timeline.start(); result = raycast_with_diag(diag, a.main().world(), pending.from, pending.to, pending.self); + time = timeline.currentFrameDuration(); } } }; diff --git a/editor/tests/region-test.cpp b/editor/tests/region-test.cpp index e17cd130..895604fb 100644 --- a/editor/tests/region-test.cpp +++ b/editor/tests/region-test.cpp @@ -8,6 +8,7 @@ #include "floormat/main.hpp" #include #include +#include namespace floormat::tests { @@ -30,6 +31,7 @@ struct result_s { std::bitset is_passable; chunk_coords_ c; + float time = 0; bool exists : 1 = false; }; @@ -113,6 +115,10 @@ void region_test::draw_ui(app&, float) std::snprintf(buf, sizeof buf, "%zu", result.is_passable.size() - result.is_passable.count()); //{ auto b = push_style_color(ImGuiCol_Text, 0xffff00ff_rgbaf); text(buf); } text(buf); + + do_column("time"); + std::snprintf(buf, sizeof buf, "%.1f ms", (double)(1000 * result.time)); + text(buf); } } @@ -152,9 +158,12 @@ void region_test::do_region_extraction(world& w, chunk_coords_ coord) { if (auto* c = w.at(coord)) { + Timeline timeline; + timeline.start(); result = { .is_passable = c->make_pass_region(true).bits, .c = coord, + .time = timeline.currentFrameDuration(), .exists = true, }; } -- cgit v1.2.3