develooper Front page | perl.perl5.porters | Postings from February 2000

Re: proposed perlpod.pod patch

Thread Previous | Thread Next
From:
sthoenna
Date:
February 7, 2000 06:06
Subject:
Re: proposed perlpod.pod patch
Message ID:
D2sn4gzkgqkR092yn@efn.org
In article <200002060004.SAA06395@agogic.cig.mot.com>,
Brad Appleton <bradapp@enteract.com> wrote:
>I also managed to get this working while allowing newlines as
>the separator without too much extra overhead. (At least I think
>so, how bad is it to do: ++$line for (/\n/g); that seems to be
>faster than: $line += split "\n"; anybody have something faster?)

[D:\]perl -w
use Benchmark;
$buf = (join '', map chr, 48..57,65..90,10) x 100;

timethese(20000,
{ for => sub { my $cnt; ++$cnt for $buf =~ m:\n:g; $cnt },
  while => sub { my $cnt; ++$cnt while $buf =~ m:\n:g; $cnt },
  split1 => sub { my $cnt; $cnt = split /\n/, $buf },
Use of implicit split to @_ is deprecated at - line 7.
  split2 => sub { my $cnt; $cnt = (() = split /\n/, $buf, -1)-1 },
  tr => sub { my $cnt; $cnt = $buf =~ tr/\n// }
});
__END__
Benchmark: timing 20000 iterations of for, split1, split2, tr, while...
       for: 130 wallclock secs (130.45 usr +  0.00 sys = 130.45 CPU) @ 153.32/s (n=20000)
    split1: 72 wallclock secs (72.66 usr +  0.00 sys = 72.66 CPU) @ 275.25/s (n=20000)
    split2: 77 wallclock secs (77.59 usr +  0.00 sys = 77.59 CPU) @ 257.77/s (n=20000)
        tr: 30 wallclock secs (29.60 usr +  0.00 sys = 29.60 CPU) @ 675.68/s (n=20000)
     while: 90 wallclock secs (90.83 usr +  0.00 sys = 90.83 CPU) @ 220.19/s (n=20000)

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About