lua-users home
lua-l archive

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


a typical loop in a vararg function using ‘select’ is quadratic with the number of arguments

Doesn’t select always spend constant time (thus making the loop linear)? A quick look at the implementation gave me that impression, but I might be wrong.

Em seg, 20 de jun de 2016 às 16:04, Roberto Ierusalimschy <roberto@inf.puc-rio.br> escreveu:

> A point that does rate some extra explanation, but perhaps iin PiL
> rather than the reference manual, is that 'select' is in fact an
> extremely efficient operation, involving no actual copying of
> arguments. There is no API equivalent, because none is needed.
> It returns the stack exactly as it found it, but reporting a possibly
> different number of return values.

That is not true. 'select' can be quite slow for a large number of
parameters (where "large" starts in the order of a few dozen). In
particular, a typical loop in a vararg function using 'select' is
quadratic with the number of arguments, while creating a table and
traversing it is linear.

-- Roberto