Script elapsed time

Can someone please drop Roblox alternative for this?

local x = os.clock()
for i=1,1000 do os.execute("true") end
print(string.format("elapsed time: %.2f\n", os.clock() - x))
6 Likes

Not super sure what os.clock() does, but from what I know it returns how many seconds a program has been runing, and it is obviously disabled in roblox. But I guess a simple alternative would be os.time which returns how much time has passed since 1970 in second. So what you can do is, save the os.time value when the game first starts, than subrtact it when the game closes or whenever you want from the latest os.time call. Another alternative would be tick()

local x = os.time()
wait(2)
print(os.time() - x) --how much time it took to wait to 2seconds

You can use this for many things, like in your example, checking how much time it takes for a for loop to loop 1000 times.

local x = os.time()
for i = 1, 1000 do print("hi") end
print(os.time() - x) --it prints exactly 1 second, which is fun

Here is a post that might help!

2 Likes
local start_time = tick()
-- code
print("This took: "..tick() - start_time.."s!")

This did the trick

9 Likes

tick() is the same thing os.time(), but it sucks because it depends on what timezone you’re on

4 Likes