Skip to content

Instantly share code, notes, and snippets.

@ItsHiatus
Last active April 15, 2023 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ItsHiatus/bbf9f8690825f8b71f5a683b78f9c622 to your computer and use it in GitHub Desktop.
Save ItsHiatus/bbf9f8690825f8b71f5a683b78f9c622 to your computer and use it in GitHub Desktop.
task scheduler test
-- Run in LocalScript context.
-- Move mouse around to see Input event ordering in the output as well.
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local lastT = os.clock()
local function FmtTime(event)
local t = os.clock()
local diff = t - lastT
if diff >= 0.01 then -- roughly the time between frames at 60 fps
print("------------------------")
end
lastT = t
print(("%.3f"):format(t), ("%.3fms"):format(math.round(diff*1000000)/1000), event)
end
-- Input
UserInputService.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
FmtTime("Input")
end
end)
-- Hearbeat
RunService.Heartbeat:Connect(function()
FmtTime("Heartbeat")
end)
-- Stepped
RunService.Stepped:Connect(function()
FmtTime("Stepped")
end)
-- RenderStepped
RunService.RenderStepped:Connect(function()
FmtTime("RenderStepped")
end)
-- Wait
while true do
wait() -- task.wait() resumes every Heartbeat, whereas wait() resumes between RenderStepped and Stepped
FmtTime("Wait")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment