The 'funny symbols' also tend to be the fastest. It was
the fastest m// routine, but I found it strange that a s///
was still faster.

As mentioned the substr is probably the best anyone can do
for performance, but for readability I would probably go
with the replace routine.
use Benchmark; $img = "http://www.my-website.be/gif/wwwtitle.gif"; timethese(1000000, { 'regexp1' => sub { my($file) = $img =~ m#.*/(.*)# }, 'regexp2' => sub { $img =~ m#[^/]+$#; my $file=$& }, 'regexp3' => sub { $img =~ m#.*/#; my $file=$' }, 'replace' => sub { $file=$img; $file =~ s#^.*/## }, 'split' => sub { my($file) = (split /\//, $img)[-1] }, 'substr' => sub { my $file = substr $img, rindex($img, '/') + 1 +} });
results:
Benchmark: timing 1000000 iterations of regexp1, regexp2, regexp3, rep +lace, split, substr... regexp1: 26 wallclock secs (20.06 usr + 0.06 sys = 20.12 CPU) regexp2: 25 wallclock secs (20.02 usr + 0.06 sys = 20.08 CPU) regexp3: 17 wallclock secs (14.83 usr + 0.04 sys = 14.87 CPU) replace: 17 wallclock secs (13.05 usr + 0.03 sys = 13.08 CPU) split: 30 wallclock secs (24.56 usr + 0.09 sys = 24.65 CPU) substr: 11 wallclock secs ( 8.46 usr + 0.02 sys = 8.48 CPU)

In reply to Re: Rexgrep by perlmonkey
in thread Rexgrep by toadi

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.