[SOLVED]Default Frames Per Second Counter Is Not Great - How To Sample Last 10 FPS Values And Take Average?


The default Frames Per Second counter is not great - it jumps around too fast and does not help.
How would I read and store the last 10 Frames Per Second values and display an average of the 10?
Let me know, thanks!


Below is what I have so far:

Hi Jesse,
I think it would be easier to simply update the text with the FPS slower. Like instead every tick you can put a timer like once every 1 second or 0.5 second.

Averaging the fps is a bit more difficult, but it’s definitely possible.
Your array is good, I think you’d need another variable to determine which array to store the current FPS value in, then another variable to add all values of the array and divide it by 10.


I need to do the following:

(1) Every second read current FPS(FPS_Current)
(2) FPS_Array[FPS_Array_Index] = FPS_Current
(3) Increment FPS_Array_Index by 1
(4) If FPS_Array_Index > 9 then FPS_Array_Index = 0
(5) Add all ten FPS_Array values and divide by 10
(6) Display average FPS to screen

I would like to do the above without coding, but do not know how to proceed.
Any help would be appreciated, thank you…


Below is as far as I can do(need some help!):


Making some progress, kinda feel like I am in the dark though…

How do I set the value of a global object variable array in JavaScript?
(Please see screenshot below)


NOTE: The array is named: “FPS_Array” and is attached to: “Text_FPS_Display”.

Can someone look at my JavaScript code below?
(It runs with no errors but the FPS display is always 0 ?

runtimeScene.getGame().getVariables().get("FPS_Current").setNumber( runtimeScene.getGame().getVariables().get("FPS_Frame_Counter").getAsNumber() );

let fpsArray = runtimeScene.getGame().getVariables().get("FPS_Array");

let fpsArrayIndex = runtimeScene.getGame().getVariables().get("FPS_Array_Index").getAsNumber();

let fpsFrameCounter = runtimeScene.getGame().getVariables().get("FPS_Frame_Counter").getAsNumber();


let fpsTotalOfTen = 0

for (let index = 0; index < 9; index++)


fpsTotalOfTen += fpsArray.getChild(index).getAsNumber();


let fpsTotalOfTenAverage = (fpsTotalOfTen / 10);

runtimeScene.getGame().getVariables().get("FPS_Array_Average").setNumber(fpsTotalOfTenAverage); // Not working - Always 0 ?

if (runtimeScene.getGame().getVariables().get("FPS_Array_Index").getAsNumber < 9)


runtimeScene.getGame().getVariables().get("FPS_Array_Index").setNumber( runtimeScene.getGame().getVariables().get("FPS_Array_Index").getAsNumber + 1 );


else runtimeScene.getGame().getVariables().get("FPS_Array_Index").setNumber(0);



hey, neat!
Unfortunately I am clueless in Javascript nowadays so I cannot assist you there.

For the screenshot with red arrows, starting the timer when the scene starts is fine.
Then move the “Change the variable” event just above the “Start (or reset) the timer” event.
Finally add a “Modify text” event to update the FPS.
(The timer is to make sure the FPS updates only once per second.)

I actually forgot how to access arrays (haven’t used GDevelop in forever), but the sigma button might help you. Wish I could help you better honestly :sweat_smile:

BTW, There’s an extension specifically for arrays, but I’ve never used it. I assume it would make this a lot easier though.

There isn’t a default FPS counter in the engine. Do you mean one of the extensions?

Also, can you give context on what is “not great” about it? To be clear, your FPS is going to fluctuate rapidly, especially if you have a game set up for 60fps max and have a monitor that has a refresh rate that isn’t 60 fps.

(All electron/browser based games are forced VSync, so if your monitor is 144 hz or 165 hz, it’ll never stay at 60fps and will normally bump down to something like 48fps)

If for some reason you absolutely must run with an average, I’d just use TimeDelta, an array, and a simple division check.

Event 1:
(No condition)     > Change the value of Scene Variable "fpsValues[Variable(frameCount)]": Set to 1/TimeDelta()
                   > Change the Text of "Text_FPS_DIsplay": Set to ToString((fpsValues[0] + fpsValues[1] + fpsValues[2] + fpsValues[3] + fpsValues[4] + fpsValues[5] + fpsValues[6] + fpsValues[7] + fpsValues[8] + fpsValues[9])/10)
                   > Change the value of Scene Variable "frameCount": Add 1

Event 2:
Scene Variable "frameCount" = 10 (since arrays start at 0 you want to reset as soon as it hits 10) > Change the value of Scene Variable "frameCount": Set to 0

Event order matters, action order matters, so the above is the order you’ll want to do this in. Keep in mind the first 10 frames will be inaccurate. Time delta counts down to sub millisecond, so expect large decimals unless you are rounding with roundTo() around the entire math expression above. You will want to pre-build the array and number variables for ease of usage.

I’ve confirmed the above works fine.

(Most monitors round up their refresh rate. My monitor’s refresh rate is 240hz but actually 239.760, which nearest divisor to 60 is roughly 59.94. Vsync will only kick in if there’s over half a frame difference from target, etc)

1 Like

Ok, that works…

I made a slight change:
I added a 1 second timer to the events.
Now the current Frames Per Second is read once every second.