lua-users home
lua-l archive

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


On 31 August 2011 11:44, HyperHacker <hyperhacker@gmail.com> wrote:
> Does math.ceil(x) in a loop seriously look up 'ceil' (and maybe even
> 'math') every time it's called? It's not smart enough to optimize that
> lookup out of a tight loop if nothing is changing it?

Yes it does. Lua does not optimize everything. The VM is small and
fast enough, AFAIK it does not do any optimization.

It's up to you to take out the lookups out of the loop. Or use LuaJIT
- it is "smart enough to optimize that lookup out of a tight loop".

This StackOverflow question may provide some insight:
http://stackoverflow.com/questions/4643814/why-would-this-lua-optimization-hack-help/