lua-users home
lua-l archive

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


Hi,

"Jakab, Steve" wrote:
> 
> When doing benchmark tests between Lua and Python, Lua beat it on almost
> every test. However, it was considerably slower on a test of passing data
> between Lua and C. Here is the Lua code:
> 
> function TestDataPass(caller)
>         local c = {}
>         c.peer = caller
> 
>         value = getData(c.peer, "testdata")
>         setData(c.peer, "testdata", value + 1)
> 
>         return c
> end
> 
> Here is the C code:
> [...]
> 
> void runtest(TestObject *obj)
> {
>         int oldtop = lua_gettop(L);
>         int result = lua_dofile(L, "TestDataPass.lua");
>         if (result != 0)
>[...] 
> I was able to call the runtest function around 30,000 times in 10 seconds,
> but similar test using Python ran 500,000 times in 10 seconds. Am I doing
> something wrong in my calls?

They main performance killer is the lua_dofile().  Did you really want
to compile the testfile for each iteration of your test (3000/s)?  You
will not be testing data passing put compilation speed :-)  Do it once
before you call runtest the first time and I guess you'll already beat
Python ;-)

And then there's the Lua code itself.  I do not know if you really want
to create a new table each time TestDataPass() is called, but the line
"local c = {}" takes approximately half of the time.  And at last, you
should make the variable "value" a local.  They are faster than globals.

Ciao, ET.