[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: the most optimal string "trim" implementation
- From: David Manura <dm.lua@...>
- Date: Mon, 28 Dec 2009 21:54:45 -0500
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 . 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.