lua-users home
lua-l archive

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


On Sat, Aug 27, 2011 at 13:56, Dimiter "malkia" Stanev <malkia@gmail.com> wrote:
> Here is one more version, still not lj2 friendly, but for some reason very
> much lua friendly (no closure, using directly next iterator):

Now that's a bit crazy. Will have read the bytecode as soon as I'll have time.

> malkia ~/p/luamarca $ ./run_benchmark.sh bench/tclone.lua 100000
> Results:
> lua
> -------------------------------------------------------------------
>                name |     rel | abs s / iter = us (1e-6 s) / iter
> -------------------------------------------------------------------
>             tclone6 |  1.0000 |   2.94 /     100000 = 29.400000 us

Five times faster? o_O

Did you try changing math.random() seed to see if it is dataset's fault?

>             tclone5 |  4.9592 |  14.58 /     100000 = 145.800000 us
>             tclone2 |  5.6190 |  16.52 /     100000 = 165.200000 us
>          lua_nucleo |  5.8401 |  17.17 /     100000 = 171.700000 us
> luajit -O
> -------------------------------------------------------------------
>                name |     rel | abs s / iter = us (1e-6 s) / iter
> -------------------------------------------------------------------
>             tclone6 |  1.0000 |   1.45 /     100000 = 14.500000 us
>             tclone5 |  1.1103 |   1.61 /     100000 = 16.100000 us
>             tclone2 |  1.3034 |   1.89 /     100000 = 18.900000 us
>          lua_nucleo |  1.5241 |   2.21 /     100000 = 22.100000 us
>
> local tclone6
> do
>  local function impl(t, visited, rtimes)
>    if visited[t] then
>      error("recursion detected")
>    end
>
>    if rtimes == 128 then
>      rtimes = 1
>      visited[t] = true
>    end
>
>    local r = {}
>    local k, v = next(t)
>    while k do

This should be: "while k ~= nil do" and may be the reason for the speedup.

Thanks,
Alexander.