I so much stand corrected! When I wrote it, I meant

my $string = pack "C*" => map { 32 + int rand 95 } 0..1280; cmpthese (-1, { subsingle => sub { (my $s = $string) =~ s/[^a-zA-Z0-9 _-]//g }, subplus => sub { (my $s = $string) =~ s/[^a-zA-Z0-9 _-]+//g }, tran => sub { (my $s = $string) =~ tr/a-zA-Z0-9 _-//cd }, });

Which gives completely different results indeed:

$ perl5.8.8 test.pl Rate subsingle subplus tran subsingle 9514/s -- -2% -90% subplus 9660/s 2% -- -90% tran 92839/s 876% 861% -- $ perl5.10.1 test.pl Rate subsingle subplus tran subsingle 7802/s -- -9% -92% subplus 8574/s 10% -- -91% tran 99211/s 1172% 1057% -- $ perl5.12.3 test.pl Rate subsingle subplus tran subsingle 5191/s -- -17% -95% subplus 6279/s 21% -- -94% tran 99211/s 1811% 1480% -- $ perl5.14.1 test.pl Rate subsingle subplus tran subsingle 6081/s -- -18% -94% subplus 7450/s 23% -- -92% tran 97303/s 1500% 1206% -- $ bleadperl test.pl Rate subsingle subplus tran subsingle 6221/s -- -12% -94% subplus 7096/s 14% -- -93% tran 97303/s 1464% 1271% -- $

So the plus indeed speeds up the substitute and tr, even in /c mode, is fastest


Enjoy, Have FUN! H.Merijn

In reply to Re^6: Remove all non alphanumeric characters excluding space, underscore and minus sign (Benchmark--) by Tux
in thread Remove all non alphanumeric characters excluding space, underscore and minus sign by ikkeniet

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.