Disabling Script Timeout?

Hello, I’m wondering how I can run loops like these…

local OneMillion = 1000000
local clock = os.clock()
for i = 1, OneMillion do
   -- test()
end
print("Time", os.clock() - clock)

without this

-- 13:05:35.119  Script timeout: exhausted allowed execution time  -  Server - Script:7

Interrupting that specific loop.

Edit:

local function test()
   -- etc..
end

-- vs

local test = function()
   -- etc..
end
-- Preferences/Readibility vs Optimization

They should finish at similar times.

Add wait()

local OneMillion = 1000000
local clock = os.clock()
for i = 1, OneMillion do 
   wait()
   -- test()
end
print("Time", os.clock() - clock)

using wait(0) also works well.

Im fairly certain it gives a delay of about 25 miliseconds.

2 Likes

If you want to increase the number as well, you need to add the increment to the for loop
for example:

local OneMillion = 1000000
local clock = os.clock()
for i = 1, OneMillion, 1 do -- Third value is the increment, in this case we're adding one 
   -- test()
   wait()
end
print("Time", os.clock() - clock)

I don’t want the loop to have a delay. I’m testing for different speed rates on functions that do similar tasks. Choosing which one is the fastest.

@Afraid4Life
Yes I know that, the default is 1 which is what I’m planning on using.

im pretty sure if you don’t want to have that delay then you’re going to have to add the increment.

Hmm… Could use coroutines.

local OneMillion = 1000000
local clock = os.clock()
local Function = coroutine.create(function()
    -- Code --
end)
for i = 1, OneMillion do 
    coroutine.resume(Function)
end
print("Time", os.clock() - clock)

It would be instantaneous.

I could but the time the function took to run 1 million times won’t be recorded.

Maybe this:

local OneMillion = 1000000
local clock = os.clock()
for i = 1, OneMillion do
    wait(1)
    -- test()
end
print("Time", os.clock() - clock - OneMillion)

This should give what you want.

You can’t disable script timeout, but you can add a yield/wait to a loop to stop it.

Timeouts exist so that the script didn’t delay task manager too much.