[SDL] Re: Frame Rates

Clemens Kirchgatterer clemens at 1541.org
Sun Oct 31 01:46:52 PDT 2004


Nick <csucew at dcs.warwick.ac.uk> wrote:

> Jakob Eklund <mailinglists <at> koalas.dk> writes:
> > On 26 Oct 2004 20:08:24 +1300, Nevyn <nevyn <at> woosh.co.nz> wrote:
> > 
> > > I know this probably sounds really stupid but I'm just about to
> > > try optimizing some code but.... well I was trying to figure out
> > > where to get the frame rate so that I could use it as a basis of
> > > comparison. Is there any quick and easy code for this?
> > 
> > It's really simple. Just use SDL_GetTicks() to messure the time
> > between  two frames.
> > Divide 1000 by the time (in milliseconds).
> 
> That'll work, though it'll bounce around a lot as the time between
> frames varies slightly. You can also have one variable storing a time,
> and another variable counting frames. Start frames at 0, and store the
> time. Each frame, put the frame counter up, and check if the current
> time is the stored time + 1000. When it is, print out the counter as
> the current FPS, then reset it to 0 and put the current time in the
> stored time. Then the FPS will update every second, showing the
> average FPS over the last second.

i posted code for this a few days ago, either it passed away unnoticed
or the mail didn't show up in the list. :) ithink this is the best
methode because it fixes two problems: it is very accurate, becaus there
are no rounding errors and it does not produce _to_many_ numbers.

regards ...
clemens




More information about the SDL mailing list