lua-users home
lua-l archive

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


On Sun, Dec 27, 2009 at 9:36 AM, Roberto Ierusalimschy wrote:
> |s:find"%S"| does the 100-time repetition at the outer level, calling
> the whole pattern-matching machinery for "%S" at every string position.
> |s:find"%s*$"| calls the machinery only once, and it does the repetition
> at the inner level, while matching %s*.
>
> BTW, the following implementation with LPEG seems to outperform the
> gsub implementations:... Its worst case is a sequence like "a ", where it
> has the same performance of gsub.

Confirmed [1].  The LPeg implementation is close to optimal bar the
case of alternating whitespace/non-whitespace, where it still performs
well.  A few Lua pattern implementations remain competitive overall,
though less-so in the case of lots of whitespace.

[1] http://lua-users.org/wiki/StringTrim