Thursday, July 9, 2009

Milliseconds vs. FPS

The Problem

Over the years, I have come to the realization that many new graphics/game programmers do not know the difference between frames per second (FPS) and milliseconds per frame (MPF), and when to use which. Most of them fall into the common pitfall of utilizing FPS as their measurement of choice when profiling and determining the efficieny of a certain algorithm. This is the wrong thing to do!

The Solution

We are going to get into a little bit of algebra. First, the definition of millisecond, better visualized as .
. The inverse of the frames per second (FPS) gives us the seconds per frame (SPF); there are 1,000 milliseconds in a second, thus multiplying by 1,000 yields the millisecond per frame (MPF).

Here is a graph that shows the milliseconds it takes to render one frame as a function of the frames per second:



As you can see, visiaully, the two values do not have a linear relationship. While the the frames per second increase, the number of milliseconds decreases at a slower rate. (In mathematical terms, as the function tends toward positive infinity its limit is 0.) What does this mean to the general programmer? The difference between 900 FPS and 870 FPS is negligible while the difference between 60 FPS and 30 FPS is quite noticeable.

The Conclusion

In summary, I will give the reader a little real world example. Your program has a pixel shader that operates on 100 pixels and gives you 1,000 FPS. You move closer to the object, now the pixel shader is operating on 150 pixels (50% more) and your framerate drops to 666 FPS. Some graphics programmers, that I have come in contact with, will think, "Oh no! I'm doing something wrong. I need to optimize my pixel shader." With our new knowledge, this change is to be expected. We have gone from 1 millisecond to 1.5 milliseconds. Now assuming that the pixel shader operation is linear and given the fact that we are shading 50% more pixels, this change in rendering speed is to be expected.

Now get out there, use those milliseconds, and never stop the crusade to help others when in need!

No comments:

Post a Comment