lua-users home
lua-l archive

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


On 2009-12-19, Miles Bader <miles@gnu.org> wrote:
> Incidentally, a simplistic benchmark:
> [..snip..]
>
>    $ time lua -e 'function f(t) return t.a+t.b+t.c end; sum = 0; for x = 1, 5000000 do sum = sum + f{a=x, b=x+1, c=x+2} end; print(sum)'
>    37500022500000
>
>    real    0m3.844s
>    user    0m3.768s
>    sys     0m0.004s
>
>
>  But with luajit, it's even more crazy (I guess since it's much easier to
>  optimize simple things like argument passing than table construction
>  etc...):
>
>    $ time luajit-2.0.0-beta2 -e 'function f(t) return t.a+t.b+t.c end; sum = 0; for x = 1, 50000000 do sum = sum + f{a=x, b=x+1, c=x+2} end; print(sum)'3.750000225e+15
>
>    real    0m13.135s
>    user    0m12.989s
>    sys     0m0.000s
>

It is surprising that LuaJIT-2.0.0 is 3 times slower than the Lua
interpreter in the case of argument table. Actually, in my tests
(Ubuntu-9.04 Linux, 2GHz DualCore x86)  LuaJIT-1.1.5 is 2 times faster
than the Lua interpreter for argument tables

* Lua-5.1.4
zsh$ time lua -e 'function f(t) return t.a+t.b+t.c end; sum=0; for x =
1,5000000 do sum=sum + f{a=x,b=x+1,c=x+2} end; print(sum)'
37500022500000
lua -e   4.06s user 0.01s system 99% cpu 4.078 total

* LuaJIT-1.1.5
zsh$ time luajit -O -e 'function f(t) return t.a+t.b+t.c end; sum=0;
for x = 1,5000000 do sum=sum + f{a=x,b=x+1,c=x+2} end; print(sum)'
37500022500000
luajit -O -e   2.22s user 0.00s system 100% cpu 2.216 total

What gives?

--Leo--