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 » Sat Jan 04, 2020 4:10 am

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: 603
Joined: Sat Dec 05, 2009 3:19 pm

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

Post by demonnic » Wed Jan 08, 2020 12:20 am

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: 603
Joined: Sat Dec 05, 2009 3:19 pm

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

Post by demonnic » Wed Jan 08, 2020 12:20 am

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

Who is online

Users browsing this forum: No registered users and 1 guest