lua-users home
lua-l archive

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


It may be worth looking at the generated Lua opcodes for these benchmarks in order to easier see the differences in what is happening in each. For example, return true v.s return nil are loadbool,return vs. loadnil,return. Then looking at the VM code for these operations, either in C or as the assembled output of the C, might make it clearer. Of course, this won't help with explaining the luajit results, as it skips the VM when JITing.

On Sat, Nov 15, 2008 at 12:57 PM, Alexander Gladysh <agladysh@gmail.com> wrote:

>> > I guess that the cost of returning function is compensated by proper tail
>> > recursion in the "chain" case, and that x1.09 slowdown of the "plain_chain"
>> > case is that cost itself.

Here are the results of somewhat related benchmark on the cost of return (code attached).

lua
-------------------------------------------------------------------
                name |     rel | abs s / iter = us (1e-6 s) / iter
-------------------------------------------------------------------
              no_ret |  1.0000 | 167.89 / 1000000000 = 0.167890 us
             ret_nil |  1.0124 | 169.97 / 1000000000 = 0.169970 us
            ret_true |  1.0425 | 175.02 / 1000000000 = 0.175020 us
            ret_self |  1.0643 | 178.68 / 1000000000 = 0.178680 us

luajit -O
-------------------------------------------------------------------
                name |     rel | abs s / iter = us (1e-6 s) / iter
-------------------------------------------------------------------
              no_ret |  1.0000 |  24.37 / 1000000000 = 0.024370 us
            ret_true |  1.0484 |  25.55 / 1000000000 = 0.025550 us
            ret_self |  1.0513 |  25.62 / 1000000000 = 0.025620 us
             ret_nil |  1.0570 |  25.76 / 1000000000 = 0.025760 us


Note ret_self means

    local function foo() return foo end

Alexander.