lua-users home
lua-l archive

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


> Alexander Gladysh wrote:
>>
>> I wonder, however, how much slower it would be against the generated
>> code version...
>
> Benchmark both of them! :)

Okay :) Here it goes.

I'm calling 10M times

  method({ a = 1, b = 2 ... z = 26 }, "a", "xxx", "z", "m", "yyy")

Methods:

* noop -- function() end
* c -- Implementation in plain C (module built with -O2 by Apple's GCC 4.0.1)
* generated -- Pregenerated version (return t[a1], t[a2]... t[aN])
* unpack -- table creation
* recursive -- Recursive call version

File kbench.lua is attached.

Results from my machine (Mac Book Pro 3.1, Intel Core 2 Duo 2.4 GHz, 2
GB RAM; OS X 10.5.4):

$ time lua kbench.lua noop 10000000
        1.47 real         1.45 user         0.00 sys
$ time lua kbench.lua c 10000000
        4.56 real         4.45 user         0.02 sys
$ time lua kbench.lua generated 10000000
        8.31 real         8.05 user         0.04 sys
$ time lua kbench.lua recursive 10000000
       21.07 real        20.63 user         0.10 sys
$ time lua kbench.lua unpack 10000000
       48.15 real        46.84 user         0.27 sys

$ time luajit -O kbench.lua noop 10000000
        0.18 real         0.18 user         0.00 sys
$ time luajit -O kbench.lua c 10000000
        2.74 real         2.69 user         0.01 sys
$ time luajit -O kbench.lua generated 10000000
        2.12 real         2.07 user         0.01 sys
$ time luajit -O kbench.lua recursive 10000000
        6.58 real         6.46 user         0.03 sys
$ time luajit -O kbench.lua unpack 10000000
       30.55 real        29.81 user         0.16 sys

Some speculations:

1. Noop for LuaJIT is hardly representative, and seems to be mostly
compilation time. Noop for plain Lua seems to represent benchmark
framework 'cost'.
2. Plain C version in LuaJIT is slower than specialized 'generated'
one in plain Lua, but still faster than any of generic versions.
3. As it was expected, creation of the table (in 'unpack') is *much*
slower than tail recursion (in 'recursive').
4. Still specialized 'generated' version is three times faster than
generic 'recursive', both under plain Lua and under LuaJIT.

BTW, can someone who have Lua and/or LuaJIT with some fancy allocator
at hand run this benchmark please? It would be interesting to see
difference between 'recursive' and 'unpack' in that case.

Alexander.

Attachment: kbench.lua
Description: Binary data