[sf-perl] Can't figure this one out

Joe Brenner doom at kzsu.stanford.edu
Wed Mar 5 19:51:46 PST 2008


Joe Brenner <doom at kzsu.stanford.edu> wrote:
> Steve Fink <sphink at gmail.com> wrote:
> > >  > By the way
> > >  >
> > >  > if ($action =~ /start/i) {
> > >  >         &MainPage($q, \%p);
> > >  > } elsif ($action =~ /new|del|edt|save/i ) {
> > >  >
> > >  > {
> > >  >
> > >  > seems better to me
> > >
> > >  It's more compact, but I bet it runs slower.  This might even be a
> > >  case where performance matters (i.e. if the cgi script sees a lot of
> > >  traffic).
> >
> > I'll take that bet. I bet the all-regex version is faster. Especially
> > on newer versions of Perl that have the trie optimization, but even
> > without that I'd guess that it's faster.
>
> And you may already be a winner.
>
> I did a quickie benchmark and it looks like the regexp alternation
> version is around 17% faster even in the "worst" cases (running on
> perl v5.8.7).  I've seen some regexps with heavy reliance on alternation
> that ran pretty slow, but this isn't one of them (and that was
> a while back in any case).

Funny thing though... just for the hell of it I ran the same code under
perl 5.10 (really, 5.9.5), and the results came out the other way, with
the alternation regexp being a bit slower (~25%) than the stack of
boolean ors.  Weird.

No, I take it back, it's not that weird: the Debian/Ubuntu version of
5.8.7 was built very differently from my 5.9.5 build:

perl 5.8.7:
  Compile-time options: MULTIPLICITY USE_ITHREADS USE_64_BIT_INT
                        USE_64_BIT_ALL USE_LARGE_FILES
                        PERL_IMPLICIT_CONTEXT

perl 5.9.5:
  Compile-time options: PERL_DONT_CREATE_GVSV PERL_MALLOC_WRAP
                        USE_64_BIT_ALL USE_64_BIT_INT USE_LARGE_FILES
                        USE_PERLIO



More information about the SanFrancisco-pm mailing list