Table array performance improvement using dot notation
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Table array performance improvement using dot notation
- From: David Crayford <dcrayford@...>
- Date: 2014年3月17日 20:20:05 +0800
I'm not sure if I have seen this documented although I know that Lua
has optimization for tables used as arrays. But I didn't expect that
would be due to using dot notation. How can this be?
local a = {}
for i = 1, arg[1] do a[i] = i * i end
DOC:/u/doc/lua: >time lua
lbench1.lua 2000000
real 0m 0.35s
user 0m 0.18s
sys 0m 0.06s
local a = {}
for i = 1, arg[1] do a.i = i * i end
DOC:/u/doc/lua: >time
lua lbench1.lua 2000000
real 0m 0.19s
user 0m 0.12s
sys 0m 0.04s