PDA

View Full Version : Displaying frames per second



ChucklesDarling
08-21-2014, 11:43 AM
Is there a piece of code that will create a window and display how many frames per second my animation is running at? Any help is appreciated!

Ruggero Visitnin
08-21-2014, 01:00 PM
Is there a piece of code that will create a window and display how many frames per second my animation is running at? Any help is appreciated!

hi, to display frame per second you have to do like this (it's pseudocode):


framerate function()
{
framecount + 1;

getCurrentTime;
if(delta_time > 1000) // delta_time = current_time - time_base
{
print(frame * 1000 / delta_time);

time_base = current_time();

framecount = 0;


}
}



so what you have to increase your frame count then get the current time check if the delta time is > 1000 print the framerate (wich corrispond to frame * 1000 / delta time) then swap the time and reset the framecount, it works for me, it should work for you

about the window all depends to what library are you using (or you want to use) and there are tens of tutorials for every library you may use...

ChucklesDarling
08-21-2014, 01:20 PM
Ohh right okay. I'll give it ago. I think I'm kind of okay with the window now, its just the fps display I was stuck on. Thanks for your help!

MtRoad
08-21-2014, 01:36 PM
When using FPS, the rate for the last second isn't necessarily the best rate. I like also to use an average over the life of the program, minimum FPS (after the program is running), and an average FPS over the last few seconds or so. This helped me pin down a specific conditions where rendering or game logic really slowed frame rate down and gave me a better idea of what FPS my programs were running at in different conditions (game levels, or with different number of enemies/game objects).

Be sure to also use a time and memory profiler (e.g. valgrind on linux) to check for other performance issues. Xcode has tools which can show if you are CPU or GPU bound, which helps a lot. Also look into gDEBugger.