Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local fs = require("filesystem")
- local Time1, Time2, TimeDiff = 0, 0, 0
- local function time()
- local f = io.open("/tmp/tps", "w")
- f:write("tps")
- f:close()
- return (fs.lastModified("/tmp/tps"))
- end
- local function cur(delay)
- Time1 = time()
- os.sleep(delay)
- Time2 = time()
- TimeDiff = Time2 - Time1
- return 20000 * delay / TimeDiff, TimeDiff
- end
- function math.median(t)
- table.sort(t)
- if math.fmod(#t,2) == 0 then
- return (t[#t * 0.5] + t[(#t* 0.5) + 1]) * 0.5
- else
- return t[math.ceil(#t * 0.5)]
- end
- end
- function math.summ(tab)
- local out = 0
- for i, n in ipairs(tab) do
- out = out + n
- end
- return out
- end
- function math.avg(tab)
- return math.summ(tab) / #tab
- end
- local function process(t, delay, max)
- if t[max] == nil then t[max] = {} end
- local t = t[max]
- if #t >= max then table.remove(t, 1) end
- t[#t + 1] = cur(delay)
- end
- local t = {}
- local function avg(delay, max)
- process(t, delay, max)
- return math.avg(t)
- end
- local t = {}
- local function median(delay, max)
- process(t, delay, max)
- return math.median(t)
- end
- return setmetatable({
- cur = cur,
- avg = avg,
- median = median
- }, {__call = function()
- return cur()
- end})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement