lua-users home
lua-l archive

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


liam mail wrote:
[...]
> See http://code.google.com/p/oolua/source/browse/trunk/profile/profile.logfor
> current speed comparisons with swig 1.3.40
> and Luabind 9.0
              ^^^ that's luabind 0.9.

Since you are making such a fuss over this I'm going to comment on your
benchmark.

First, it isn't very clear what you are trying to measure. For instance,
the first benchmark - "access" - is simply calling two member functions.
Why is it called "access"? "virtual function" and "pure virtual
function" measure the exact same thing. Why?

But more importantly, *all* of your benchmarks are mixing in the cost of
fetching a member from an object. This is the primary reason your code
appears to perform better. Rewriting:

  for ...
    x:f()
  end

as

  local f = x.f
  for ...
    f(x)
  end

will give a more meaningful benchmark, as it actually measures the cost
of the call, rather than the lookup.

The reason lookups in OOLua is so fast is that __index doesn't call into
C++. Both Swig and luabind does, because they both support "properties".

Further, there is essentially no error checking. For primitive types,
the error check consists of an assert(), so in the release build there
is no checking at all. For both Swig and luabind, calling a function
with the wrong parameter type will give a meaningful error, and at least
for primitive types there is no way of turning this off. For luabind at
least, this is by design.

OOLua also doesn't verify that the userdata it gets from Lua is actually
a OOLua-wrapper. But to be fair, neither does Swig. I guess not doing
this might be OK if you can completely trust the Lua code that you run.
luabind 0.9 has no way of turning this check off, but my working copy
does (it's a one line change).

If you make the lookup change as I outlined above to your benchmarks,
and make the error checking of userdata in luabind equal to that of
OOLua and Swig:

diff --git a/src/object_rep.cpp b/src/object_rep.cpp
index 6977bee..75c32bb 100755
--- a/src/object_rep.cpp
+++ b/src/object_rep.cpp
@@ -244,6 +244,8 @@ namespace luabind { namespace detail
     {
         object_rep* result = static_cast<object_rep*>(lua_touserdata(L,
index));

+        return result;
+
         if (!result || !lua_getmetatable(L, index))
             return 0;

I think you will get very different results. On my machine, this makes
OOLua slower than both luabind and Swig on every one of your benchmarks.

-- 
Daniel Wallin
BoostPro Computing
http://www.boostpro.com