[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: table.unpack question.
- From: Pierre-Yves Gérardy <pygy79@...>
- Date: Sat, 25 May 2013 19:06:29 +0200
On Sat, May 25, 2013 at 6:42 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> 2013/5/25 Pierre-Yves Gérardy <pygy79@gmail.com>:
> LUAI_MAXSTACK (see `luaconf.h`) less what you are already using.
> Which depends.
>
> It would be easy to do in C. The critical information is hidden from the
> API, you only have `checkstack`. But even with that you could extract
> the information by a bargaining process as the `#` function does.
So you can't determine it from the Lua side.
I'm trying to write a max(array) function that's as fast as possible.
In Lua 5.1 and 5.2, and LuaJIT -joff, math.max(unpack(array)) is by
far the fastest method, but it can blow up unpredictably.
I though that I could use a numeric threshold to decide whether to use
unpack() or to iterate manually. Dispatching based on pcall(unpack,t)
pays for tables with a length superior to ~30. I may use that.
Thanks for the help.