Re: Performance luabind vs. SWIG

liam mail <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
2009/11/27 Tony Kostanjsek <[email protected]>

> Did you enable any optimization switches for the build? IIRC template
> inlining doesn't kick in unless you switch on -O2 or something, and you can
> tweak additional inlining parameters.
>
> ----- Ursprüngliche Mail ----
> Von: Sebastian Wolff <[email protected]>
> An: [email protected]
> Gesendet: Freitag, den 27. November 2009, 17:39:35 Uhr
> Betreff: [luabind] Performance luabind vs. SWIG
>
> Hello list,
>
> Since I did not find any speed comparisons on bindings to Lua I decided
> to run a little test for a simple class implementation using SWIG and
> luabind.
>
> Here is the class:
>
> namespace tmmod
> {
>    class TMMatrix;
>
> //     #ifndef SWIG
>
>    class TMMatrix{
>        public:
>            TMMatrix(int i, int j) {}
>            TMMatrix operator+(const TMMatrix & rhs)const{}
>            void func1(int i){}
>            void func2(int i){}
>            void func3(int i){}
>            void func4(int i){}
>            void func5(int i){}
>            void func6(int i){}
>            void func7(int i){}
>
>    };
>
>
>    #ifndef SWIG
>    void open_lib_TM(lua_State *myLuaState);
>    #endif
>
>    void external_matrix_method(TMMatrix & mat);
>
> }
>
> and here the luabind code:
>
>    void open_lib_TM(lua_State *myLuaState)
>    {
>        luabind::module(myLuaState, "luabind")         [
>            luabind::class_<TMMatrix>("TMMatrix")
>                .def(luabind::constructor<int,int>())
>                .def("func1",&TMMatrix::func1)
>                .def("func2",&TMMatrix::func2)
>                .def("func3",&TMMatrix::func3)
>                .def("func4",&TMMatrix::func4)
>                .def("func5",&TMMatrix::func5)
>                .def("func6",&TMMatrix::func6)
>                .def("func7",&TMMatrix::func7)
>                .def(luabind::self + luabind::other<TMMatrix>())
>        ];
>
>
>    }
>
> The wrapper code for SWIG is simply "%include matrix.hpp"
>
> The functions do not anything - I only wanted to know the speed of the
> binding: So I ran through the following example:
>
> n = 1e6
>
> print("time at start: " .. TNG.Time())
>
> mat2 = luabind.TMMatrix(3,3)
> for i=1,n do
>        matrix = luabind.TMMatrix(3,3)
>        mat2 = matrix+luabind.TMMatrix(3,3)
>        mat2 = matrix+luabind.TMMatrix(3,3)
>        mat2:func1(1)
>        mat2:func3(1)
>        mat2:func7(1)
> end
>
> print("time after luabind: " .. TNG.Time())
>
> mat2 = tm.TMMatrix(3,3)
> for i=1,n do
>        matrix = tm.TMMatrix(3,3)
>        mat2 = matrix+tm.TMMatrix(3,3)
>        mat2 = matrix+tm.TMMatrix(3,3)
>        mat2:func1(1)
>        mat2:func3(1)
>        mat2:func7(1)
> end
>
> print("time after SWIG: " .. TNG.Time())
>
>
> and got:
>
> luabind: 9.4 sec
> swig:    4.78 sec
>
> This is quite astonishing since I thought that template magic may be
> able to speed up things. I did not use any special -D's, luabind was
> used as provided by my vendor (opensuse x64).
>
> I only wanted the list you know this. Maybe someone picks it up to
> finde some room for improvement in luabind.
>
> Sebastian
>
>
>
>
>
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus
> on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> luabind-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
>
> __________________________________________________
> Do You Yahoo!?
> Sie sind Spam leid? Yahoo! Mail verfügt über einen herausragenden Schutz
> gegen Massenmails.
> http://mail.yahoo.com
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus
> on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> luabind-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>

I do not know the internals of either swig or luabind but I have a couple of
observations about this test.
Firstly it is a bogus profiling, anything class such as vector or matrix
should have a plain Lua implementation for speed reasons especially if you
are going to call it this many times.
Secondly I can only guess but I would assume this test calls the new
operator 5 million times. Does luabind work this way? ie when a new class is
created does it call new in C++ code?
Thirdly how did you even get the code to compile as you have a addition
operator which does not return anything yet is defined as returning an
instance.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july

_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.