lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hey

On 16 March 2017 at 12:56, Soni L. <fakedme@gmail.com> wrote:

I do `local tinsert = table.insert` for performance.

This always seems to be the argument, but is it actually valid?

I just benchmarked table.insert vs a local alias, in a loop, with one million iterations, and the difference was 0.01s

So I says to myself I says, Chris, that was a 4GHz i7, that's not necessarily fair. Repeat the test on a Raspberry Pi 2B and the difference is 0.16s.

This rather suggests to me that even on a very low end processor, the cost of individual global table lookups is so tiny that it's not worth the effect it has on the programmer who has to deal with the aliases. That's just me though :)

Cheers,
Chris