#GitHub - seantheman1/Gfps: A simple impr...

1 messages · Page 1 of 1 (latest)

elder wasp
#

this is a bad implementation that does not really work well
first of all, floating point has limited precision and doing 1 / frametime is suboptimal
what you can do is simply:

---@const
local historySeconds = 1

local frames = { }
local function onFrame()
  local t = SysTime()
  while frames[1] < t - historySeconds do
    table.remove(frames, 1)
  end

  table.insert(frames, t)
end

and then use the frames variable as the source of frame times to do the math
for the current fps, you simply get the count after onFrame: #frames
for the average frametime, calculate differences between records and... average them
for the average fps, keep a history of the fps values at each frame for some time
etc etc, you get it

the provided implementation is, however, not the most efficient, but its good enough xd

pure lodge
#

I’ll have to give that a try thanks for the optimization side of things

#

If u wanna change anything i posted it on GitHub you could make a pull request

#

@elder wasp Thanks

elder wasp
pure lodge
#

Alright

elder wasp
# pure lodge Alright
local historySeconds = 10

-- do note that this only works till the 2^51 (or 52?)st frame, and then probably stops working right due to FP precision
local frames = {
  bottom = 0, top = 0,
  list = { }
}

local function onFrame()
  local t = SysTime()

  -- remove records that are too old
  local list = frames.list
  local bottom = frames.bottom
  while list[bottom] and list[bottom] < t - historySeconds do
    list[bottom] = nil
    bottom = bottom + 1
  end
  frames.bottom = bottom

  local top = frames.top + 1
  frames.top = top
  list[top] = t
end

-- some examples
-- (all assume there is at least one frame)

-- how many frames are recorded
do
  print(frames.top - frames.bottom)
end

-- how much time is recorded
do
  print(frames.list[frames.top] - frames.list[frames.bottom])
end

-- how may frames have passed in the last N seconds
local function frameCount(interval)
  local t = SysTime() - interval

  local list = frames.list
  local intervalBottom
  for i = frames.bottom, frames.top do
    if frames[i] >= t then
      intervalBottom = i
      break
    end
  end

  return intervalBottom and frames.top - intervalBottom
end

i think that will be way more efficient
less overhead for counting, less overhead for inserting/removing frames in the history

pure lodge
#

Currently I’m not at my pc but when I get to it I’ll make some changes

glacial jasper
#

you may want to write the description yourself instead of chatgpt-ing it

Performance Optimization: Provides insights into potential bottlenecks and optimization suggestions

it's an fps display not a profiler

marsh loom
#

Use color_white?

honest wadi
#

Copilot moment

#

Nah jk, sometimes I get recommended that and I'm like "that's white bro"

#

It would be personally a good thing to implement 1% and 5%, mins really doesn't help a lot because it doesn't give the full picture since a stutter might trigger it, in places where it shouldn't be accounted as gameplay

#

But the % would

#

I couldn't implement it on mine

pure lodge
#

I just put white since it easier to remember but yeah lol

pure lodge
#

Odd I removed that early I probably forgot to make a GitHub commit

pure lodge
pure lodge
#

I fixed the GitHub page and steam.

polar walrus
#

“This addon does not currently support public servers” ??

glacial jasper
#

Your description also states it uses the MIT license while the license file is GPLv2

#

Again you may want to strongly consider writing the description yourself, it's a simple enough addon

pure lodge
pure lodge
#

If u want feel free to check the description again as I’ve fixed any issue related to that

#

I’ll be updating the add on to support customization. Afterwards I’ll be adding 1% low and 5% lows, to show more performance metrics.

glacial jasper