It is too bad that people posting "benchmark" code so rarely take the care to validate that the numbers that they are posting actually have any meaning behind them. For example, when you get a "Rate" like "3918166/s", then you should probably just throw away your benchmark results as having no practical meaning.

In this particular case, this was a hint that your $s = $s x 10_000_000­; line was completely pointless because of other aspects of your code. Fixing that problem (and reducing the string size significantly so it will finish before I need to go to bed), gives:

#!perl use strict; use warnings; use Benchmark qw( cmpthese ); use English qw( -no_match_vars ); local $OUTPUT_RECORD_SEPARATOR = "\n"; print 'Perl version: ', $PERL_VERSION; my $s = 'Aid bears out ' x 10_000; print 'Length of string: ', length $s; cmpthese( -1, { 'lc' => sub { () = lc($s) =~ m{ [aeiou][aeiou] }xms +g }, '[Aa][Aa]' => sub { () = $s =~ m{ [AaEeIiOoUu][AaEeIiOoUu] }xms +g }, '[Aa]{2}' => sub { () = $s =~ m{ [AaEeIiOoUu]{2} }xms +g }, '/i' => sub { () = $s =~ m{ (?i) [aeiou]{2} }xms +g }, } ); __END__
Perl version: v5.12.0 Length of string: 140000 Rate [Aa]{2} lc [Aa][Aa] /i [Aa]{2} 50.7/s -- -0% -1% -3% lc 50.8/s 0% -- -1% -3% [Aa][Aa] 51.5/s 1% 1% -- -2% /i 52.5/s 4% 3% 2% --

which shows how the performance differences are minimal (and the actual difference you'll see in the performance of a real script will be even smaller than that).

So the "which will become noticable" assertion was wrong.

Update: Here, here! Learning++, (Good attitude)++.

- tye        


In reply to Re^5: Vowel search (benchmarks--) by tye
in thread Vowel search by Noob@Perl

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.