lua-users home
lua-l archive

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


This is a quick test with Lua4 vs. Lua5 (the script is at the very bottom). Both executables are in release built generated by VC6 under Win32@Win2000. Here are the outputs

Lua4 (local f) - the function f was declared as local
0.625 
0.75   
Lua5 (local f)
0.813
1.015
Lua4 (global f) - the function f was NOT declared as local
0.75  
0.75  
Lua5 (global f)
0.843 
1.032 

Aside from the fact that Lua4 is simply faster on function calls by up to 30% (.625 vs. 813), tag-method calls have the same performance as global function calls in Lua4. In Lua5, however, the meta-method has another 22% overhead over global function calls. The tag methods of Lua4 are 37% faster than meta-mehods in Lua5. 

Is the test good enough? If it is I am even more surprised than I had expected. I wonder how other platforms would measure on this.

Of course this test doesn't imply that real world applications will suffer from these differences. But it does illustrate my point and beyond. I would imagine that on any custom class hierarchy (inheritance chains) created with Lua5 the slowdown would be noticeable. If someone wanted to emulate "__get"/"__set" using proxy tables the difference to tag-methods performance would have been even greater.

AB
-----Original Message-----
From: Roberto Ierusalimschy [mailto:roberto@inf.puc-rio.br]
Sent: Wednesday, January 29, 2003 1:28 AM
To: Multiple recipients of list
Subject: Re: On lua5 and embedding 

> Basically, as long as one runs plain vanilla Lua5 scripts they will
> go pretty fast. But as soon as one starts using inheritance, call and
> other meta-methods on their objects that is when the meta-method
> overhead jumps in.

Can you give us your performance measures and details of your tests
(platform, etc.)? In our own tests, we did not detect any significant
difference between tag methods in Lua 4.0 and metamethods in Lua 5.0b.

-- Roberto

-- ====== "__call" / "function" event timing script ==============================
local f = function ()
--f = function ()
end

TAG = newtag()
settagmethod(TAG, "function", f)
local t = {}
settag(t, TAG)
--local mt = {__call = f}
--setmetatable(t, mt)

c = clock()
for i = 1, 100000 
do
   f()
   f()
   f()
   f()
   f()

   f()
   f()
   f()
   f()
   f()

   f()
   f()
   f()
   f()
   f()

   f()
   f()
   f()
   f()
   f()

   f()
   f()
   f()
   f()
   f()

   f()
   f()
   f()
   f()
   f()
end
print(clock()-c)

c = clock()
for i = 1, 100000 
do
   t()
   t()
   t()
   t()
   t()

   t()
   t()
   t()
   t()
   t()

   t()
   t()
   t()
   t()
   t()

   t()
   t()
   t()
   t()
   t()

   t()
   t()
   t()
   t()
   t()

   t()
   t()
   t()
   t()
   t()
end
print(clock()-c)