FPS counter

How do I build one ?

FPS = frames per second = number of frames divided by total seconds elapsed time. And there you have it.

Look for QueryPerformanceCounter() if you’re
on windows, setitimer() if you’re on linux,
or system_time() if you’re on BeOS.

I use thw windows API function GetTickCount(), that returns the number of miliseconds passed since you started Windows (since you started Windows or your application, I’m not sure). You can play with this function to retrieve the time from one frame to another.

The problem with GetTickCount() is that it’s
only millisecond accurate. If you’re
running at 100 fps (a good goal :slight_smile: then
there’s only 10 ticks per frame, so your
precision quantization will be a full 10%
of your counter!

QueryPerformanceCounter() typically gives you
about microsecond resolution, and the
precision loss from using the counter drops
to 0.01% or less – definitely down in the
noise.

If you’re targeting pentium-class or higher
CPUs, QueryPerformanceCounter() is always
available, so it’s usually the best way to
go. (Myself, I decided that MMX is a
requirement, which guarantees performance
counters, too)