The Console displays the value of FP.frameRate
each update. FP.frameRate
is set during Engine.render()
, and is based on an averaged value of frame times for each of the frames in the frame list.
The way it is tracked is fairly simple.
- Get the elapsed time of the frame.
- Add this time to the previous frame times.
- Store this time.
- If the number of stored frame times is greater than 10, remove the first one added from the list and subtract this time from the previous frame times.
- Calculate the average frame time across the last 10 frames.
- Convert this number into frames per second.
What this does is provide a sliding window of the 10 most recent frame times. This is the FPS value that you see in the Console.
To answer your question, since this is an average of 10 frame times, you may see the FPS spike if you have a very long frame time get dropped and a very short frame time gets added. Take a look at this:
f0Β Β f1 f2 f3 f4Β Β f5Β Β f6Β Β f7Β Β f8Β Β f9Β Β | fSumΒ Β fAvg FPS
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ+ββββββββββββββββββββ
frame0 80ms 16ms 16ms 16ms 16ms 16ms 16ms 16ms 16ms 16ms | 240ms 24ms 42 fps
frame1 16ms 16ms 16ms 16ms 16ms 16ms 16ms 16ms 16ms 8ms | 152msΒ 15msΒ 66 fps
frame2 16ms 16ms 16ms 16ms 16ms 16ms 16ms 16msΒ 8ms 26ms | 162msΒ 16msΒ 60 fps
In three frames, the frame rate starts at 42 fps, spikes to 66 fps, then returns to 60 fps, even though most of the frames are running at 16ms (60 fps).