What is the average fps for a finished app?

Here’s a line of code that displays the FPS in the upper right corner of the screen. Change the 2 in %.2f to a value from 0 to 6 to show the number of rounded decimal places you want to see.


text(string.format("%.2f",1/DeltaTime),WIDTH-50,HEIGHT-25)

I was curious about the accuracy of the code FPS = FPS * 0.9 + 0.1 / DeltaTime. So here is another graph showing in RED, the running total of ( 1/DeltaTime ) divided by the count of ( 1/DeltaTime ). That should give the actual average of ( 1/DeltaTime ) or average frames per second. The WHITE graph shows the calculation of FPS = FPS * 0.9 + 0.1 / DeltaTime. I’m also printing the information in the output window to put a strain on the draw() function, causing it to slow down. I set d=DeltaTime at the start of draw() so that I’m using the same value for both calculation. As the graph shows, the calculated FPS is a lot lower than the actual average fps. I’m also showing both values in the parameter.watch window.


supportedOrientations(LANDSCAPE_ANY)

function setup()
    textMode(CORNER)
    total=0
    count=0
    parameter.watch("FPS")
    parameter.watch("total/count")
    backingMode(RETAINED)
    strokeWidth(2)
end

function draw()
    d=DeltaTime
    if FPS == nil then 
        fill(255)
        text("60 fps",300,610)
        text(50,300,510)
        text(40,300,410)
        text(30,300,310)
        text(20,300,210)
        line(20,600,WIDTH,600)
        line(20,500,WIDTH,500)
        line(20,400,WIDTH,400)
        line(20,300,WIDTH,300)
        line(20,200,WIDTH,200)
        FPS = 1/d
        total=1/d
        count=1
        fill(255,0,0)
        text("Total of (1/d ) divided by the count of (1/d )   Actual average.",200,HEIGHT-50)
        fill(255)
        text("Calculated   FPS = FPS * 0.9 + 0.1 / d",200,HEIGHT-100)
        print(count,1/d,total,FPS,total/count)
    else 
        FPS = FPS * 0.9 + 0.1 / d
        total=total+(1/d)
        count=count+1
        print(count,1/d,total,FPS,total/count)
    end
    stroke(255)
    ellipse(count/5,FPS*10,2)
    stroke(255,0,0)
    ellipse(count/5,total/count*10,2)
end