Okay, I tried a bunch of different things. Two sets of the same tests, one for 3 seconds, the other 6.
use Benchmark; timethese(-3, { aa => sub { $string = "blah+blah+blah"; $string =~ tr/+/ /; }, bb => sub { $string = "blah+blah+blah"; $string =~ s/\+/ /g; }, cc => sub { $string = "blah+blah+blah+blah+blah+blah"; $string =~ tr/+/ /; }, dd => sub { $string = "blah+blah+blah+blah+blah+blah"; $string =~ s/\+/ /g; }, ee => sub { $string = "blah"; $string =~ tr/+/ /; }, ff => sub { $string = "blah"; $string =~ s/\+/ /g; }, }); print "\n"; timethese(-6, { aa => sub { $string = "blah+blah+blah"; $string =~ tr/+/ /; }, bb => sub { $string = "blah+blah+blah"; $string =~ s/\+/ /g; }, cc => sub { $string = "blah+blah+blah+blah+blah+blah"; $string =~ tr/+/ /; }, dd => sub { $string = "blah+blah+blah+blah+blah+blah"; $string =~ s/\+/ /g; }, ee => sub { $string = "blah"; $string =~ tr/+/ /; }, ff => sub { $string = "blah"; $string =~ s/\+/ /g; }, });
The preceding output the following:
Benchmark: running aa, bb, cc, dd, ee, ff, each for at least 3 CPU sec +onds... aa: 6 wallclock secs ( 2.91 usr + 0.10 sys = 3.01 CPU) @ 42 +9021.93/s (n=1291356) bb: 8 wallclock secs ( 2.95 usr + 0.05 sys = 3.00 CPU) @ 20 +8165.00/s (n=624495) cc: 8 wallclock secs ( 2.90 usr + 0.10 sys = 3.00 CPU) @ 40 +4326.00/s (n=1212978) dd: 7 wallclock secs ( 2.88 usr + 0.12 sys = 3.00 CPU) @ 13 +4898.33/s (n=404695) ee: 8 wallclock secs ( 3.21 usr + 0.02 sys = 3.23 CPU) @ 50 +7243.96/s (n=1638398) ff: 6 wallclock secs ( 3.05 usr + -0.04 sys = 3.01 CPU) @ 60 +3128.24/s (n=1815416) Benchmark: running aa, bb, cc, dd, ee, ff, each for at least 6 CPU sec +onds... aa: 11 wallclock secs ( 5.87 usr + 0.14 sys = 6.01 CPU) @ 45 +1358.24/s (n=2712663) bb: 11 wallclock secs ( 5.99 usr + 0.01 sys = 6.00 CPU) @ 22 +2497.00/s (n=1334982) cc: 12 wallclock secs ( 6.12 usr + 0.01 sys = 6.13 CPU) @ 45 +0148.29/s (n=2759409) dd: 11 wallclock secs ( 6.39 usr + 0.02 sys = 6.41 CPU) @ 14 +9619.66/s (n=959062) ee: 12 wallclock secs ( 5.97 usr + 0.03 sys = 6.00 CPU) @ 52 +0242.00/s (n=3121452) ff: 7 wallclock secs ( 6.01 usr + 0.00 sys = 6.01 CPU) @ 60 +7347.25/s (n=3650157)
So by the looks of the runs per second statistic that tr is indeed faster than s///. What dondelelcaro mentioned about v5.005003 having a slower version of tr could be relevant though, as that is what I'm running.

Amel - f.k.a. - kel


In reply to Re: Re: Re: Re: transliterate by dsb
in thread transliterate by Anonymous Monk

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.