develooper Front page | perl.perl5.porters | Postings from August 2008

[perl #58280] Speed lost on /^(foo|bar|baz)$/ match

Thread Next
From:
Steve Peters via RT
Date:
August 27, 2008 07:07
Subject:
[perl #58280] Speed lost on /^(foo|bar|baz)$/ match
Message ID:
rt-3.6.HEAD-29762-1219806970-1236.58280-15-0@perl.org
On Fri Aug 22 15:28:29 2008, schwern wrote:
> 
> This is a bug report for perl from schwern@pobox.com,
> generated with the help of perlbug 1.39 running under perl 5.11.0.
> 
> 
> -----------------------------------------------------------------
> [Please describe your issue here]
> 
> I was testing out an efficiency claim and discovered that 5.10 and
> bleadperl have both lost a lot of performance on /^(foo|bar|baz)$/
> type regexes.
> 
> #!/usr/bin/perl -w
> 
> use strict;
> use warnings;
> 
> use Benchmark qw(cmpthese);
> 
> my $token = "open";
> 
> cmpthese(shift || -3, {
>     regex       => sub { $token =~ m/\A (?: open | close | read )
>    \z/xms; },
>     regex_opt   => sub { $token =~ m/^(?:open|close|read)$/; },
>     eq          => sub { $token eq 'open' ||
>                          $token eq 'close' ||
>                          $token eq 'read';
>                    }
> });
> 
> $ bleadperl ~/tmp/bug.plx  5000000
>                Rate regex_opt     regex        eq
> regex_opt 1222494/s        --       -5%      -85%
> regex     1282051/s        5%        --      -84%
> eq        8064516/s      560%      529%        --
> 
> $ perl5.8.8 ~/tmp/bug.plx  5000000
>                Rate regex_opt     regex        eq
> regex_opt 3048780/s        --       -1%      -54%
> regex     3086420/s        1%        --      -53%
> eq        6578947/s      116%      113%        --
> 
> $ perl5.10.0 ~/tmp/bug.plx  5000000
>                 Rate     regex regex_opt        eq
> regex      1492537/s        --       -0%      -89%
> regex_opt  1497006/s        0%        --      -89%
> eq        13157895/s      782%      779%        --
> 
> Can anyone duplicate?
> 
Yes, I can duplicate.  The first is 5.8.8.  The second is bleadperl.  

Steve Peters
steve@fisharerojo.org

steve@picard:~/perl-current$ perl bench.pl 5000000
               Rate regex_opt     regex        eq
regex_opt 1886792/s        --       -0%      -61%
regex     1893939/s        0%        --      -61%
eq        4807692/s      155%      154%        --
steve@picard:~/perl-current$ ./perl -Ilib bench.pl 
               Rate regex_opt     regex        eq
regex_opt 1016789/s        --       -2%      -85%
regex     1035642/s        2%        --      -84%
eq        6569214/s      546%      534%        --


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