lua-users home
lua-l archive

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



>> > 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.

Attachment: returnbench.lua
Description: Binary data