Page 1 of 1

matches[n] faster then a local variable?

Posted: Sat Jan 04, 2020 4:10 am
by rand
Is matches[n] faster then accessing a local variable? For example:

for i=1,100 do
echo("Backstab "..matches[2])
end

OR

local s = matches[2]
for i=1,100 do
echo("Backstab "..s)
end

Thanks.

Re: matches[n] faster then a local variable?

Posted: Wed Jan 08, 2020 12:20 am
by demonnic
the local is faster, generally speaking. But you're unlikely to see much of a real difference until you get to thousands of iterations of the loop.

Re: matches[n] faster then a local variable?

Posted: Wed Jan 08, 2020 12:20 am
by demonnic
That being said there's good reason to use a local just for more readable code, too. Though not if you use variable names like 's' so much.