I get slightly different results:

$ perl -le' open D, q[/usr/share/dict/words] or die $!; my $string = join "|", <D>; use Benchmark qw/cmpthese/; cmpthese -20, { orig => sub { my @arr = split /\|/, $string; my @arr1 = grep { /oug/ } @arr; return @arr1; }, Buk1 => sub { my @arr1 = grep { /oug/ } split /\|/, $string; return @arr1; }, jwkrahn => sub { my @arr1 = grep /oug/, split /\|/, $string; return @arr1; }, Buk2 => sub { my @arr1 = $string =~ /(?:^|\|)(.*?oug.*?)(?=\||$)/g; return @arr1; }, JOOST => sub { my @arr1 = $string =~ /(?:^|\|)([^|]*?oug[^|]*?)(?=\||$)/g; return @arr1; }, }; ' Rate JOOST Buk2 orig Buk1 jwkrahn JOOST 4.37/s -- -10% -13% -38% -67% Buk2 4.87/s 11% -- -4% -31% -63% orig 5.05/s 15% 4% -- -28% -62% Buk1 7.05/s 61% 45% 40% -- -47% jwkrahn 13.2/s 202% 171% 162% 87% --
  YMMV   :-)


In reply to Re^4: Performance optimization question by jwkrahn
in thread Performance optimization question by vit

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.