lua-users home
lua-l archive

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


Title: Message
Sorry, just to be clear, let me finish the examples:
 
mytable = {prop1 = X, prop2 = Y}
...
foo = mytable.prop1
bar = mytable.prop2
-- etc
 
vs
 
prop1 = 1
prop2 = 2
mytable = {[prop1] = X, [prop2] = Y}
...
foo = mytable[prop1]
bar = mytable[prop2]
-- etc
 
It's not the performance of creating the tables that I'm worried about, but rather all the accesses to the table contents.
-----Original Message-----
From: Curt Carpenter
Sent: Monday, June 25, 2001 10:31 AM
To: 'lua-l@tecgraf.puc-rio.br'
Subject: Performance of key lookups

Hi all. Has anyone done any performance evaluation of key lookups? Specifically, I'm using Lua in an environment where performance of script execution will be important, and I'm thinking of avoiding string keys completely for performance reasons, and instead planning on having numeric globals, so that instead of
 
mytable = {prop1 = X, prop2 = Y}
 
I'd have
 
prop1 = 1
prop2 = 2
mytable = {[prop1] = X, [prop2] = Y}
 
At first I thought it would be a slam dunk in terms of performance, but then I realized that the second approach requires a global lookup instead of a key lookup, which is essentially the same thing (?) plus the numeric key index. So maybe the second approach is actually worse?
 
Any insights into the absolute most efficient way to index tables would be appreciated. Using no keys, however, is probably not an option.
 
Thanks,
 
Curt