diff --git a/examples/PoolBox/application/src/Overlay/Overlay.hpp b/examples/PoolBox/application/src/Overlay/Overlay.hpp index d5ccc809..5f78e8f6 100644 --- a/examples/PoolBox/application/src/Overlay/Overlay.hpp +++ b/examples/PoolBox/application/src/Overlay/Overlay.hpp @@ -1,4 +1,14 @@ #pragma once +#include +#include + namespace Overlay { - void mesaure_busy_loop(); + namespace TimerTest { + using TimeStamp = JabyEngine::HighResTime::TimeStamp; + + void mesaure_busy_loop(); + + TimeStamp start_measuring(); + void end_measuring(const TimeStamp& start, size_t data_samples); + } } \ No newline at end of file diff --git a/examples/PoolBox/application/src/Overlay/TimerTests/timer_tests.cpp b/examples/PoolBox/application/src/Overlay/TimerTests/timer_tests.cpp index 45de067f..72510819 100644 --- a/examples/PoolBox/application/src/Overlay/TimerTests/timer_tests.cpp +++ b/examples/PoolBox/application/src/Overlay/TimerTests/timer_tests.cpp @@ -1,18 +1,40 @@ -#include -#include - -#pragma GCC warning "Enable this code to verify that high percision counter is still functional" -extern "C" void busy_loop(int count); -namespace Overlay { - void mesaure_busy_loop() { - static constexpr auto Counts = 500; - - JabyEngine::HighResTime::enable(); - const auto start = JabyEngine::HighResTime::get_time_stamp(); - busy_loop(Counts); - const auto end = JabyEngine::HighResTime::get_time_stamp(); - JabyEngine::HighResTime::disable(); - - printf("Busy loop of %i took %ims %ins\n", Counts, start.milliseconds_to(end), start.microseconds_to(end)); - } +#include "../Overlay.hpp" +#include + +extern "C" void busy_loop(int count); + +namespace Overlay { + namespace TimerTest { + static size_t avg = 0; + static size_t cur_rounds = 0; + + void mesaure_busy_loop() { + static constexpr auto Counts = 500; + + JabyEngine::HighResTime::enable(); + const auto start = JabyEngine::HighResTime::get_time_stamp(); + busy_loop(Counts); + const auto end = JabyEngine::HighResTime::get_time_stamp(); + JabyEngine::HighResTime::disable(); + + printf("Busy loop of %i took %ims %ins\n", Counts, start.milliseconds_to(end), start.microseconds_to(end)); + } + + TimeStamp start_measuring() { + return JabyEngine::HighResTime::get_time_stamp(); + } + + void end_measuring(const TimeStamp& start, size_t data_samples) { + const auto end = JabyEngine::HighResTime::get_time_stamp(); + + avg += start.microseconds_to(end); + cur_rounds++; + if(cur_rounds == data_samples) { + printf("AVG Time: %ius\n", avg/cur_rounds); + + avg = 0; + cur_rounds = 0; + } + } + } } \ No newline at end of file diff --git a/examples/PoolBox/application/src/main.cpp b/examples/PoolBox/application/src/main.cpp index 0d266f20..cd0cc4c4 100644 --- a/examples/PoolBox/application/src/main.cpp +++ b/examples/PoolBox/application/src/main.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include using namespace JabyEngine; @@ -35,28 +34,15 @@ static void render() { } void main() { - static constexpr size_t MaxRounds = 1; - - size_t avg = 0; - size_t cur_rounds = 0; setup(); - Overlay::mesaure_busy_loop(); + Overlay::TimerTest::mesaure_busy_loop(); JabyEngine::HighResTime::enable(); while(true) { - const auto start = JabyEngine::HighResTime::get_time_stamp(); - update(); - render(); - const auto end = JabyEngine::HighResTime::get_time_stamp(); - - avg += start.microseconds_to(end); - cur_rounds++; - if(cur_rounds == GPU::Display::frames_per_sec) { - printf("AVG Time: %ius\n", avg/MaxRounds); - - avg = 0; - cur_rounds = 0; - } + const auto start = Overlay::TimerTest::start_measuring(); + update(); + render(); + Overlay::TimerTest::end_measuring(start, GPU::Display::frames_per_sec); } } \ No newline at end of file