in reply to Re^4: Vowel search
in thread Vowel search

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        

Replies are listed 'Best First'.
Re^6: Vowel search (benchmarks++ after all)
by AnomalousMonk (Archbishop) on Jun 12, 2014 at 04:03 UTC

    I was a bit reluctant to post Re^4: Vowel search because I wasn't sure it was a real contribution to the discussion. Now I'm happy I did because I learned something, even if only not to slap myself in the forehead quite so hard when I realize I've done something stupid. So ++benchmarks!