The speed depends on the length of the string.
Here's my modified benchmark:
#!/perl/bin/perl # # bench.pl -- use strict; use warnings; use diagnostics; use Benchmark qw(:all); my $str = '|0' x (shift @ARGV || 100_000); sub caseone { $_ = $str; s/.//; } sub casetwo { $_ = $str; substr($_,0,1) = ''; } sub casethree { $_ = $str; $_ = reverse $_; chop; $_ = reverse $_; } sub casefour { $_ = $str; $_ = substr($_,1); } cmpthese(-2, { 'regex' => 'caseone', 'substr_mod' => 'casetwo', 'reverse' => 'casethree', 'susbtr_copy' => 'casefour', });
# string length 2 * 10: Rate reverse regex substr_mod susbtr_copy reverse 797484/s -- -29% -30% -41% regex 1125463/s 41% -- -1% -16% substr_mod 1131927/s 42% 1% -- -16% susbtr_copy 1344489/s 69% 19% 19% -- # string length 2 * 100_000: Rate reverse susbtr_copy regex substr_mod reverse 1385/s -- -51% -60% -80% susbtr_copy 2847/s 106% -- -17% -58% regex 3437/s 148% 21% -- -49% substr_mod 6771/s 389% 138% 97% -- # with 2 * 1e7: Rate reverse susbtr_copy regex substr_mod reverse 8.61/s -- -54% -58% -81% susbtr_copy 18.7/s 117% -- -8% -58% regex 20.4/s 137% 9% -- -54% substr_mod 44.6/s 418% 139% 119% --

The speed doesn't really depend on the perl version (I tried 5.8.8 and 5.10.0).


In reply to Re: Ways to delete start of string by moritz
in thread Ways to delete start of string by hsmyers

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.