diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2026-07-10 10:55:13 +0200 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2026-09-04 11:06:23 +0200 |
| commit | c212b34cc12c69fd380e0b1a2ed3bbf41826345d (patch) | |
| tree | d6aa97767eea2049ca195934e539dc6594e26cbc /samples/SampleApp.cpp | |
| parent | 78092ce771c506873b2839b70ad7c488a01535c3 (diff) | |
add time measure in samples
Diffstat (limited to 'samples/SampleApp.cpp')
| -rw-r--r-- | samples/SampleApp.cpp | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/samples/SampleApp.cpp b/samples/SampleApp.cpp index 3ac7e64..16bf11b 100644 --- a/samples/SampleApp.cpp +++ b/samples/SampleApp.cpp @@ -1,5 +1,6 @@ #include <iostream> #include <stdio.h> +#include <chrono> #include "vkvg.h" #include "vkh.h" @@ -183,6 +184,9 @@ void SampleApp::Run() { int testIdx = 0; auto it = VkvgTest::tests.begin(); VkvgTest* curTest = NULL; + std::vector<double> run_time_values; + run_time_values.reserve(iterations); + double totTime = 0; if (testsToRun.empty()) { curTest = (*it); @@ -191,24 +195,41 @@ void SampleApp::Run() { } glfwSetWindowTitle(win, curTest->name.c_str()); + curTest->initTest(this); + curTest->performTest(testIdx);//warm-up while (!glfwWindowShouldClose(win)) { glfwPollEvents(); - curTest->performTest(); + int idx = testIdx; + auto start = std::chrono::steady_clock::now(); + DoNotOptimize(idx); + int res = curTest->performTest(idx); + DoNotOptimize(res); + auto finish = std::chrono::steady_clock::now(); + + auto elapsed = finish - start; + /*double elapsed_ms = std::chrono::duration_cast<std::chrono::milliseconds>( + elapsed).count();*/ + double elapsed_ms = std::chrono::duration<double, std::milli>(elapsed).count(); + if (!vkh_presenter_draw(renderer)) { vkh_presenter_get_size(renderer, &width, &height); - curTest->cleanTest(); + curTest->cleanTest(0, nullptr); curTest->initTest(this); + curTest->performTest(testIdx);//warm-up continue; } if (iterations > 0) { + totTime += elapsed_ms; + run_time_values.push_back(elapsed_ms); + if (++curIter == iterations) { + curTest->cleanTest(totTime, run_time_values.data()); testIdx++; - curTest->cleanTest(); if (testsToRun.empty()) { if (++it == VkvgTest::tests.end()) { curTest = NULL; @@ -224,13 +245,17 @@ void SampleApp::Run() { } curIter = 0; + totTime = 0; + run_time_values.clear(); + run_time_values.reserve(iterations); glfwSetWindowTitle(win, curTest->name.c_str()); curTest->initTest(this); + curTest->performTest(testIdx);//warm-up } } } if (curTest != NULL) - curTest->cleanTest(); + curTest->cleanTest(totTime, run_time_values.data()); } void SampleApp::CleanUp() { |