Is there a way to check the speeds of roblox integrated functions like, findfirstchild or waitforchild of how fast it runs?

Iā€™m trying to check the speed of how fast it is for a function like FindFirstChild or WaitForChild or anyother integrated functions that roblox has and how fast it runs. Help is appreciated :slight_smile:

1 Like

So a benchmark test?

A simple version of it is to get the current CPU time, run whatever code you need for a few thousand iterations, and then calulate the elapsed time.

It would look something like this:

local startTime = os.clock(); -- CPU Time is more accurate for this

for i = 1,10000 do -- run 10000 iterations
    -- a single iteration wont fully determine its speed
    -- however within this loop, you put the code that you want to run and test it
end

local elasped = os.clock() - startTime; -- Calulate the elasped time since loop
-- elapsed will always be bigger than start.
print(`This function took {elasped}s to run`); -- print result

I would expect :FindFirstChild() to be much faster, as it does not yield like :WaitForChild().

1 Like

I mean this does work just everytime i run it, it prints out a different integer of how long it took.

-- Record the initial time:
local startTime = os.clock()
-- Do something you want to measure the performance of:
local a, b = 0, 1
for i = 1, 5000000 do
    a, b = b, a
end
-- Measure amount of time this took:
local deltaTime = os.clock() - startTime
print("Elapsed time: " .. deltaTime)
-->  Elapsed time: 0.044425600033719 (actual number may vary)

In other words, make a start time, do whatever you want to test the length of, and then print out the current time minus original time, that should show you how long it took to do the thing

The number is not always going to be the same, It never will ne either.