What formula is used to calculate FPS in a game?

Posted on

Question :

I’m creating a game in java using lwjgl3, I’ve seen many algorithms but they’re all different from each other.

So simplifying my code would be like this:




What formula could I use to calculate fps in the game?


Answer :

The frame rate per second (FPS or QPS) can be calculated as follows:

public void start() {
    lastFPS = getTime();

public void updateFPS() {
    if (getTime() - lastFPS > 1000) {
        Display.setTitle("FPS: " + fps); 
        fps = 0; //reseta o contador de FPS
        lastFPS += 1000; //adiciona um segundo

The FPS representation is simple, it’s how many frames were displayed in a single second. The frame rate per second is 30, which means that in one second, 30 frames were displayed.

The formula in a basic representation would be: FPS = (number of frames) / (number of seconds) . For example, if
120 seconds were displayed 6400 frames, our FPS would be ± 53,333 (6400/120).

The Display.setTitle(String title) is for simplicity, showing the counter in the window title.

More information on the documentation .


Leave a Reply

Your email address will not be published. Required fields are marked *