Creating Frames per Seconds

Discussion in 'iOS Programming' started by Kingbombs, Jun 25, 2009.

  1. Kingbombs macrumors member

    Jun 24, 2009

    So i want to show my Frames per Second on my iPhone Simulator.
    I know that i should have a count and increment it by one each time it enters the drawView method (im in OpenGL ES)

    but what timer class should i use?
    Looking at NSTimer and not to sure how to use it.

    I want the timer class to check if a second has passed when in the drawView method, and if so then show the count and set the count to 0.

    Then keep checking if another second has passed.

    What time class should i use? and how should it be used (if its NSTimer then im not to sure how to lay it out)

    Thanks in advance!
  2. admanimal macrumors 68040

    Apr 22, 2005
    Why not do it this way:

    initialize a counter to 0. Record the current time of day (using NSDate).
    Every time drawView is called, increment the counter.

    If the counter reaches some number...say 25 or 50, see what time it is now and subtract the starting time from that to see how many (milli)seconds have passed. Then divide the counter by the difference in times to get your frames per second. Reset the counter to 0, save the now current time, and repeat.

    So rather than directly trying to count how many frames you can draw in a second, you are just going ahead and drawing a bunch of frames, and then seeing how long it took.

Share This Page