refactor(lib/utils): simplify tps calculation
This commit is contained in:
parent
41b3375749
commit
dfac6e0413
@ -45,30 +45,28 @@ function entity_speed(uuid, seconds)
|
|||||||
return speed
|
return speed
|
||||||
end
|
end
|
||||||
|
|
||||||
function tps(seconds)
|
function tps(ms)
|
||||||
if not seconds then
|
if not ms then
|
||||||
seconds = 1
|
ms = 1000
|
||||||
end
|
end
|
||||||
|
|
||||||
add_listener("tick", function()
|
add_listener("tick", function()
|
||||||
if not TpsTracking.ticks then
|
if not TpsTracking.ticks then
|
||||||
TpsTracking.ticks = 0
|
TpsTracking.ticks = 0
|
||||||
TpsTracking.start = clock_gettime(0)
|
sleep(ms)
|
||||||
|
TpsTracking.result = TpsTracking.ticks
|
||||||
|
remove_listeners("tick", "tps_tracking")
|
||||||
else
|
else
|
||||||
TpsTracking.ticks = TpsTracking.ticks + 1
|
TpsTracking.ticks = TpsTracking.ticks + 1
|
||||||
if TpsTracking.ticks >= seconds * 20 then
|
|
||||||
TpsTracking.stop = clock_gettime(0)
|
|
||||||
remove_listeners("tick", "tps_tracking")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end, "tps_tracking")
|
end, "tps_tracking")
|
||||||
|
|
||||||
sleep(seconds * 1000)
|
sleep(ms)
|
||||||
repeat
|
repeat
|
||||||
sleep(20)
|
sleep(20)
|
||||||
until TpsTracking.stop
|
until TpsTracking.result
|
||||||
|
|
||||||
local tps = seconds * 20 / (TpsTracking.stop - TpsTracking.start)
|
local tps = TpsTracking.result / (ms / 1000)
|
||||||
TpsTracking = {}
|
TpsTracking = {}
|
||||||
return tps
|
return tps
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user