• Advertisement


This topic is now archived and is closed to further replies.

how to calculate fps

This topic is 6391 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here's an easy way to do it.

1. increment a variable (int) after a frame is drawn (usually at the bottom of your game loop)

2. Calculate when 1 second (use GetTickCount or similar) has elapsed. (you'll need two variables one for the current time and one for the original time [1 second earlier])

3. After 1 second has elapsed the variable will represent the frames per second. You can then store this value in another variable to display it on the screen, calculate average fps. Reset the variable (set it = to 0).

4.The process begins again.

Here's some psuedo code


// end of loop


if(current_time - original_time >= 1000)
fps_previous = fps; // stores fps value

original_time = GetTickCount();


Edited by - +AA_970+ on July 22, 2000 2:41:40 PM

Share this post

Link to post
Share on other sites
well i tried to implement your method and i set all variables to 0 but all i get is a one displayed

Share this post

Link to post
Share on other sites
Howa bout dis, straight out my own Engine


//Frames Per Second = Num Frame / Elasped Time in Seconds

class CFPS_Counter {
DWORD StartTime; //The Start Time

DWORD CurrTime; //Current Time

DWORD NumFrame; //Number of Frames since start

float Fps; //Current Frames Per Second

float Spf; //Current Seconds Per Frame

char FPSstring[128];//Dont Overflow<img src="smile.gif" width=15 height=15 align=middle>

unsigned long delay;

int StartFPS(); //Starts the FPS Counter

int UpdateFPS(); //Updates the Fps Variable

float ReturnFPS(){return Fps;} //Returns the Fps variable

int DrawFPS();
//Returns the Speed Per Frame from the Num per second

float NumPerSecond(float in){return in*Spf;}

//Draws the FPS

int CFPS_Counter::DrawFPS()
if(sprintf(FPSstring,"%f",ReturnFPS())<=0)return FALSE;

return TRUE;

int CFPS_Counter::StartFPS()
StartTime = GetTickCount();
return TRUE;

int CFPS_Counter::UpdateFPS()
float tempFPS;
CurrTime = GetTickCount();
tempFPS = 1000.0f*((float)NumFrame/((float)CurrTime-(float)StartTime));
Spf = 1/tempFPS;


return TRUE;

Hope it helped

Share this post

Link to post
Share on other sites

  • Advertisement