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

Re: [PATCH] Remove implicit split to @_

Thread Previous | Thread Next
From:
Michael G Schwern
Date:
July 10, 2009 14:28
Subject:
Re: [PATCH] Remove implicit split to @_
Message ID:
4A57B281.1000606@pobox.com
--------------070006030104000008050701
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.

--------------070006030104000008050701
Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0";
 name="bench.plx"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="bench.plx"

#!/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;
        $count++;
        return $count;
    },
#     tr  => sub {
#         my $count = $string =~ tr/\n//;
#         $count++;
#         return $count;
#     },
});

--------------070006030104000008050701--

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