Skip to content

Instantly share code, notes, and snippets.

@Mischa-Alff
Last active January 26, 2023 04:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Mischa-Alff/bf1fbd248b116765fc57 to your computer and use it in GitHub Desktop.
Save Mischa-Alff/bf1fbd248b116765fc57 to your computer and use it in GitHub Desktop.
std::chrono::high_resolution_clock::time_point start, end, timetoprint;
timetoprint = start = end = std::chrono::high_resolution_clock::now();
long long frame_count=0;
long double frametime_total=0.f;
while(!glfwWindowShouldClose(win)) {
end = std::chrono::high_resolution_clock::now();
long int frametime_us = (std::chrono::duration_cast<std::chrono::microseconds>(end-start).count());
float frametime_s = ft/1e6f;
frametime_total += frametime_us;
++frame_count;
if(std::chrono::duration_cast<std::chrono::seconds>(end-timetoprint).count() >= 1) {
timetoprint = std::chrono::high_resolution_clock::now();
float frametime_avg = frametime_total/count;
float fps_avg = 1e6f/frametime_avg;
std::wstring frametimestr = L"FPS avg: "+std::to_wstring(fps_avg) + L"\t" L"Frametime avg: "+std::to_wstring(frametime_avg)+L"µs\n";
wlog.log(frametimestr);
count=0;
frametime_total=0;
}
start=end;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment