lua-users home
lua-l archive

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

On 10-Oct-05, at 1:31 PM, Chris Marrin wrote:

Adam D. Moss wrote:
Posti Laatikko wrote:
Since lua is intepreted language i was wondering does variables & funtions
names effect execution speed if names are long?
Nope - they're just strings which are interned and then
compared/hashed by pointer.

But technically a long string takes longer to do the initial hash, right? So I can imagine a situation where a string must be interned at runtime (constructed on-the-fly) and where you might see some runtime performance issues for long strings vs. short strings.

It's hard to imagine a scenario where you're creating a string at runtime which is not at least O(n) on the size of the string you're creating. However, Lua's hash function only examines a maximum number of character (*not* the first k characters, but rather k characters spread through the string), so it is not dependent on the length of the string. Arguably, there are more collisions with long strings as a result of the partial hashing, but I haven't actually observed this in practice.