I was just curious about it, so here you go:
#!/usr/bin/perl use strict; use warnings; use Benchmark qw( cmpthese ); my @data = split /\n/, <<END; 800-800-1212 (800)800-1212 (800) 800-1212 800 800 1212 END sub dosloop { my $re = shift; (my $phone = $_) =~ s/$re//g foreach @data; } sub doyloop { my $fake = shift; (my $phone = $_) =~ y/0-9//cd foreach @data; } cmpthese(-10, { single => sub { dosloop(qr/\D/) }, multiple=> sub { dosloop(qr/\D+/) }, y => sub { doyloop(qr/\D/) }, # Just a fake parameter } );
I tried to be as fair as possible and have the same overhead for all calls. The results are the following:
Rate multiple single y multiple 95932/s -- -6% -39% single 101881/s 6% -- -35% y 156303/s 63% 53% --
The simple translation outperforms the other, as expected. I was particularly curious about putting the '+' or not. I vaguely remember some discussion about it before, but I couldn't tell you where.

Flavio
perl -ple'$_=reverse' <<<ti.xittelop@oivalf

Don't fool yourself.

In reply to Benchmark time: Numbers only in a string by polettix
in thread Numbers only in a string by powerhouse

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.