FPS (FRAMES PER SECOND)

by Nightwolf Introduction

Hello! This article is written esspecially for people wanting to see how fast the engine of their new program is but have no idea how to do it. I'll first explain what FPS is then I'll discuss what a good FPS rate is for your program and then I'll give an example program which measures FPS.

What is FPS?

FPS stands for Frames Per Second, this means how many times the program refreshes the image on the monitor. A more efficiently written program has a higher FPS rate than a sloppy program. The higher the FPS rate the smoother the program runs.

What is a good FPS rate for my program?

The human can see about 23 FPS so for a smooth looking animation you need to have a FPS greater than this. A FPS about 25 is the bare minimum for smooth animations. A FPS of about 40 or 50 should be fine for most programs. The highest useable FPS you can get is around 70, while you CAN get higher FPS it won't help to smoothen the animation because the monitor refreshes only 70 times a second.

OK, now how do I implent this into my program?

Ahh! Now the nice part comes :) I'll have source code in a minute but first I need to explain something about the implentation of FPS in a program. In order to measure FPS your program needs to refresh continuasly. This means that the program has, for instance, a DO...LOOP in which all the actions are called (check for user input, move the player, redraw the screen). If your program is a like this you can add a FPS counter if your program only redraws the screen when, for instance, the player moves the FPS counter is fairly useless.

OK, onto the source code! So you have this DO...LOOP in your program. Add this somewhere in the LOOP.

        FPS% = FPS% + 1
        IF starttime# + 1 < TIMER THEN
         FPS2% = FPS%
         FPS% = 0
         starttime# = TIMER
        END IF
This will put the FPS of your program in the FPS2% variable after a second or so. To view the FPS you could simply do:
        LOCATE 1,1
        PRINT FPS2%
I'll discuss the code line by line now:
        FPS% = FPS% + 1
Increase FPS% by 1
        IF starttime# + 1 < TIMER THEN
Starttime# is the variable in which we store the current value of TIMER. If this value plus 1 (one second) is smaller than the current times (this means one second has passed) we enter the IF...THEN
         FPS2% = FPS%
Give FPS2% the value of FPS%, we can't just PRINT FPS% to the screen because it would be increasing all the time.
         FPS% = 0
Give FPS% the value of 0, to start the count all over again.
         starttime# = TIMER
Give starttime# the (new) current value of TIMER.
        END IF
End if.

Well... I hope you understand FPS now. If anything's not clear. Mail me!


© Copyright 1999-2000 The QB Times.
This tutorial was taken from The QB Times with permission from the webmaster(s) of the site. You may not take this article and place it on any other website.