Skip to content

Commit 8c1f373

Browse files
authored
Merge pull request #12 from TECHNICANGEL/perf/optimize-window-title-update-1226180534073299234
⚡ Optimize window title update frequency to 4Hz
2 parents 75140bf + 871efd7 commit 8c1f373

2 files changed

Lines changed: 41 additions & 8 deletions

File tree

benchmark_snprintf.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <cstdio>
2+
#include <chrono>
3+
#include <iostream>
4+
5+
int main() {
6+
const int iterations = 1000000;
7+
char title[256];
8+
float currentFPS = 60.0f;
9+
float frameTimeMs = 16.66f;
10+
uint32_t totalSamples = 12345;
11+
float posX = 10.5f, posY = -5.2f, posZ = 100.1f;
12+
13+
auto start = std::chrono::high_resolution_clock::now();
14+
15+
for (int i = 0; i < iterations; ++i) {
16+
snprintf(title, sizeof(title),
17+
"IZTAPALAPA PATH TRACER | FPS: %.0f | %.2fms | %u samples | Pos: (%.1f, %.1f, %.1f)",
18+
currentFPS, frameTimeMs, totalSamples, posX, posY, posZ);
19+
}
20+
21+
auto end = std::chrono::high_resolution_clock::now();
22+
std::chrono::duration<double> elapsed = end - start;
23+
24+
std::cout << "Time for " << iterations << " snprintf calls: " << elapsed.count() << "s\n";
25+
std::cout << "Average time per call: " << (elapsed.count() / iterations) * 1e6 << " microseconds\n";
26+
27+
return 0;
28+
}

src/main.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@ class RacingEngine {
769769
int fpsFrameCount = 0;
770770
float currentFPS = 0.0f;
771771
float frameTimeMs = 0.0f;
772+
float titleUpdateTimer = 0.0f;
772773

773774
// Initialize temporal accumulation tracking
774775
lastCameraPos = camera.getPosition();
@@ -838,14 +839,18 @@ class RacingEngine {
838839
acceleration.prepareInstanceData(device, transforms);
839840
}
840841

841-
// Update window title with stats every frame
842-
glm::vec3 pos = camera.getPosition();
843-
char title[256];
844-
uint32_t totalSamples = accumulationFrames * 8; // 8 SPP per frame
845-
snprintf(title, sizeof(title),
846-
"IZTAPALAPA PATH TRACER | FPS: %.0f | %.2fms | %u samples | Pos: (%.1f, %.1f, %.1f)",
847-
currentFPS, frameTimeMs, totalSamples, pos.x, pos.y, pos.z);
848-
glfwSetWindowTitle(window, title);
842+
// Update window title with stats every 0.25s
843+
titleUpdateTimer += deltaTime;
844+
if (titleUpdateTimer >= 0.25f) {
845+
glm::vec3 pos = camera.getPosition();
846+
char title[256];
847+
uint32_t totalSamples = accumulationFrames * 8; // 8 SPP per frame
848+
snprintf(title, sizeof(title),
849+
"IZTAPALAPA PATH TRACER | FPS: %.0f | %.2fms | %u samples | Pos: (%.1f, %.1f, %.1f)",
850+
currentFPS, frameTimeMs, totalSamples, pos.x, pos.y, pos.z);
851+
glfwSetWindowTitle(window, title);
852+
titleUpdateTimer = 0.0f;
853+
}
849854

850855
#if ENABLE_RENDER_LOOP_LOGGING
851856
// Print detailed status to console periodically

0 commit comments

Comments
 (0)