matches[n] faster then a local variable?

Post Reply
rand
Posts: 2
Joined: Sat Jan 04, 2020 2:08 am

matches[n] faster then a local variable?

Post 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.

User avatar
demonnic
Posts: 667
Joined: Sat Dec 05, 2009 3:19 pm

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

Post 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.

User avatar
demonnic
Posts: 667
Joined: Sat Dec 05, 2009 3:19 pm

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

Post 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.

Post Reply