[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Table performance
- From: Jack Christensen <jack@...>
- Date: Tue, 04 May 2004 18:37:08 -0500
I'm trying to do as much as possible in Lua before I run into
performance problems and have to drop back to C++. As part of the tests
I was running I came across some surprising (to me anyway) results.
Am I doing something wrong or is it rather expensive to access to a table?
The following two blocks for code are identical except that one loop has
two table accesses in it. The one with tables runs at less then half the
speed.
local x, y, i = 0, 3, 0
while i < 500000 do
x = i * y
i = i + 1
end
local t = { x = 0, y = 3 }
local i = 0
while i < 500000 do
t.x = i * t.y
i = i + 1
end
I also tried binding a simple C++ class with luabind and running the
equivalent loop. It was about 10 times slower than the table loop above.
Jack