Finding the average frames-per-second (FPS) of an entire animation

Animations aren't always smooth and depending on the number of objects, their complexity and eventually the number of lights, the quality of the shadows and the various visual effects, we can observe widely varying frame rates. Sometimes at one moment the FPS meter can show 8fps and several hundred milliseconds later we can see more than 25fps. What does this tell about our animation? Can we easily compare how changes in our code affect "slow" segments of the animation by observing them over multiple runs? Which version would perform "better"—an animation that is slow in segment A, but fast in segment B or one which has become fast in segment A, but at the expense of getting slower in segment B?

Looking at the fast-changing FPS meter can stand in the way of seeing the big picture. This means that it may be more beneficial to see how different runs of the animation compare to each other in terms of a single FPS number describing the entire sequence of frames. Only after we know that the whole sequence performs better, can we conclude something about the quality of the changes we have made to the code.

This question was adressed on the Real-time rendering blog and in the Interactive 3D graphics MOOC. People have also mentioned that it is more accurate to measure milliseconds/frame rather than FPS. An example how to determine the FPS of the entire animation was also given, although the result may not seem very intuitive.

To illustrate the problem, assume that you know the FPS and the number of frames for five different segments of your animation and you want to find a single representative FPS number. You can fill your own data for each segment and then check whether the data you expect to see is correct.

FPS for frames
FPS for frames
FPS for frames
FPS for frames
FPS for frames

What is the average speed of the animation?