Last active
April 15, 2023 16:46
-
-
Save ItsHiatus/bbf9f8690825f8b71f5a683b78f9c622 to your computer and use it in GitHub Desktop.
task scheduler test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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