develooper Front page | perl.perl5.porters | Postings from July 2009

Re: [PATCH] Remove implicit split to @_

Thread Previous | Thread Next
Michael G Schwern
July 10, 2009 14:28
Re: [PATCH] Remove implicit split to @_
Message ID:
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Michael G Schwern wrote:
> It also means we can optimize it to just count the fields and not store an
> array.  And everyone loves optimizations!

Irony of ironies, split() in scalar is already faster in 5.10.0 than m/.../g
for the few common cases I've thrown at it, long or short string.

That's without optimizations or even removing the @_ behavior.  Imagine what
happens when someone with more C foo than me optimizes the scalar context case
to just be a regex count loop!

I have a date with some giant cartoon robots and booze.

Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0";
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;

#!/usr/bin/perl -w

use strict;
use warnings;

use Benchmark qw(cmpthese);

open my $fh, "<", "/usr/share/dict/words" or die $!;
my $long_string = join "", <$fh>;
my $string = "aflkjalkdhbhba;lkjb;lakldsfh";

cmpthese(shift || -3, {
    split => sub {
        my $count = split /a+/, $string;
        return $count;
    regex_g => sub {
        my $count = () = $string =~ m/a+/g;
        return $count;
#     tr  => sub {
#         my $count = $string =~ tr/\n//;
#         $count++;
#         return $count;
#     },


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About