lua-users home
lua-l archive

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


Hi, Dimiter,

On Sat, Aug 27, 2011 at 14:24, Dimiter "malkia" Stanev <malkia@gmail.com> wrote:
> On 8/27/11 3:09 AM, Alexander Gladysh wrote:
>>
>> 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.
>
> Reading the lua docs and wiki it seems that pairs() returns a closure,
> table, and key. The closure is the next iterator.
>
> Now here I'm directly calling the function next(table, key), instead of the
> returned closure from pairs(). Probably I'm not doing something legal
> (metatables? metatable iterators (lua 5.2)?)

No, that's perfectly legal in 5.1 as far as I know.

> Check it again, I can't be sure.

Can't reproduce your results. I think that mistake in while condition
(while k instead of while k ~= nil) is to blame — your dataset
probably contained a lot of data behind false key.

I pushed the fixed benchmark to the GitHub, try it for yourself.

$ ./run_benchmark.sh bench/tclone.lua 1e6
Results:
lua
-------------------------------------------------------------------
                name |     rel | abs s / iter = us (1e-6 s) / iter
-------------------------------------------------------------------
             tclone5 |  1.0000 | 184.09 /    1000000 = 184.090000 us
             tclone6 |  1.0112 | 186.15 /    1000000 = 186.150000 us
             tclone2 |  1.1218 | 206.52 /    1000000 = 206.520000 us
          lua_nucleo |  1.2242 | 225.37 /    1000000 = 225.370000 us
luajit2
-------------------------------------------------------------------
                name |     rel | abs s / iter = us (1e-6 s) / iter
-------------------------------------------------------------------
             tclone6 |  1.0000 |  19.90 /    1000000 = 19.900000 us
             tclone5 |  1.0111 |  20.12 /    1000000 = 20.120000 us
             tclone2 |  1.2181 |  24.24 /    1000000 = 24.240000 us
          lua_nucleo |  1.3558 |  26.98 /    1000000 = 26.980000 us

Alexander.