lua-users home
lua-l archive

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


On Thu, Feb 14, 2013 at 11:53 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> 2013/1/23 Coda Highland <chighland@gmail.com>:
>
>>
>> My statement stands: table.concat() is the fastest way to do it.
>> There's no other way to do it without exposing yourself to quadratic
>> behavior.
>>
>
> What about a C function that simply calls lua_concat on the whole
> stack and passing it table.unpack(tbl) as argument list? Faster,
> slower, much the same? (Of course, the semantics is then
> different: metamethods may be called.)
>

It's hard to make a comparison in the source code because they're VERY
different-looking functions. My intuition says that it would be linear
performance still but having to check for metamethods at all would
slow it down and I'm not sure how much impact would come from the
behavior of unpack(). Rule of thumb here is profile, profile, profile.

In LuaJIT, on the other hand, the winner is probably going to be
table.concat, since using a Lua C API function would abort
compilation. The actual concat operation may have similar discussions
to vanilla Lua but the effects on the surrounding code may be
problematic.

/s/ Adam