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

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

From:
Michael G Schwern
Date:
August 23, 2008 04:21
Subject:
[perl #58280] Speed lost on /^(foo|bar|baz)$/ match
Message ID:
rt-3.6.HEAD-29759-1219444109-709.58280-75-0@perl.org
# New Ticket Created by  Michael G Schwern 
# Please include the string:  [perl #58280]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=58280 >



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?


[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=low
---
Site configuration information for perl 5.11.0:

Configured by schwern at Fri Aug 22 15:15:47 PDT 2008.

Summary of my perl5 (revision 5 version 11 subversion 0 patch 34218) configuration:
  Platform:
    osname=darwin, osvers=8.11.1, archname=darwin-thread-multi-2level
    uname='darwin windhund.schwern.org 8.11.1 darwin kernel version 8.11.1: wed oct 10 18:23:28 pdt 2007; root:xnu-792.25.20~1release_i386 i386 i386 macbook1,1 darwin '
    config_args='-de -Dprefix=/usr/local/perl/blead -Dusedevel -Duseithreads -Dccflags=-I/sw/include -Dldflags=-L/sw/lib -Dperladmin=schwern@pobox.com -Dcf_email=schwern@pobox.com -Dmyhostname=windhund -Dmydomain=.schwern.org -Dlibpth=/usr/local/lib /sw/lib /opt/local/lib /usr/lib -Uversiononly -Uinstallusrbinperl'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=undef, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-I/sw/include -fno-common -DPERL_DARWIN -no-cpp-precomp -fno-strict-aliasing -pipe -I/usr/local/include -I/opt/local/include',
    optimize='-O3',
    cppflags='-no-cpp-precomp -I/sw/include -fno-common -DPERL_DARWIN -no-cpp-precomp -fno-strict-aliasing -pipe -I/usr/local/include -I/opt/local/include'
    ccversion='', gccversion='4.0.1 (Apple Computer, Inc. build 5370)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags ='-L/sw/lib -L/usr/local/lib -L/opt/local/lib'
    libpth=/usr/local/lib /sw/lib /opt/local/lib /usr/lib
    libs=-lgdbm -ldbm -ldb -ldl -lm -lc
    perllibs=-ldl -lm -lc
    libc=/usr/lib/libc.dylib, so=dylib, useshrplib=false, libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-L/sw/lib -bundle -undefined dynamic_lookup -L/usr/local/lib -L/opt/local/lib'

Locally applied patches:
    DEVEL

---
@INC for perl 5.11.0:
    /sw/lib/perl5/darwin-thread-multi-2level
    /sw/lib/perl5
    /sw/lib/perl5/darwin
    /usr/local/perl/blead/lib/5.11.0/darwin-thread-multi-2level
    /usr/local/perl/blead/lib/5.11.0
    /usr/local/perl/blead/lib/site_perl/5.11.0/darwin-thread-multi-2level
    /usr/local/perl/blead/lib/site_perl/5.11.0
    /usr/local/perl/blead/lib/site_perl/5.10.0
    /usr/local/perl/blead/lib/site_perl
    .

---
Environment for perl 5.11.0:
    DYLD_LIBRARY_PATH (unset)
    HOME=/Users/schwern
    LANG (unset)
    LANGUAGE (unset)
    LC_CTYPE=en_US.UTF-8
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/Users/schwern/bin:/usr/local/bin:/opt/local/bin:/opt/local/sbin:/sw/bin:/sw/sbin:/Users/schwern/bin:/usr/local/bin:/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin
    PERL5LIB=/sw/lib/perl5:/sw/lib/perl5/darwin
    PERL_BADLANG (unset)
    SHELL=/bin/bash




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