On Mon, 13 Aug 2001, Ian Phillipps wrote:
> On Mon, 13 Aug 2001 at 12:13:23 +0300, Ilmari Karonen wrote:
>
> > * For any nontrivial text input, the "1 while s/\s\z//" approach is by
> > far the fastest.
>
> How about "chop while /\s\z/" ?
Fast, but not quite as fast as "1 while s/\s\z//".
$ pe '" "x1024' | perl rtrim2.pl -30
Benchmark: running _null, chop, rep-z, each for at least 30 CPU seconds...
_null: 32 wallclock secs (29.98 usr + 0.02 sys = 30.00 CPU) @ 170790.77/s
(n=5123723)
chop: 32 wallclock secs (30.18 usr + 0.01 sys = 30.19 CPU) @ 349.62/s (n=10555)
rep-z: 33 wallclock secs (30.91 usr + 0.02 sys = 30.93 CPU) @ 415.52/s (n=12852)
Factoring out the assignment cost, "1 while s/\s\z//" would seem to be
about 1.2 times as fast as "chop while /\s\z/".
--
Ilmari Karonen - http://www.sci.fi/~iltzu/
"For added entertainment, maybe even set a limit on the number of sets of
clothing and gear each team can use, but allow an unlimited number of
players." -- Anthony de Boer in the monastery