in reply to Re^2: Alternative matches
in thread Alternative matches
I tested this just to make sure . . . there was a savings of approx 2 seconds (21 vs 23)
Usually we like to see Benchmark code to back up this type of assertion. Using a the setup from PodMaster's (i.e. generating a random $string to test against), I get the following results, which seem to validate your results:
$ perl match Rate orig lc orig 1492/s -- -7% lc 1608/s 8% -- $ perl match Rate orig lc orig 1506/s -- -7% lc 1620/s 8% -- $ perl match Rate orig lc orig 1492/s -- -8% lc 1627/s 9% --
And, in case you want to test this for yourself (or modify it to be more accurate to what you're doing), here's the code:
use strict; use Benchmark qw(cmpthese); my $pattern = '(new|old|number|start|simple|cross|heavy|die|exit)'; my @words = qw( new Old Number start Simple Cross heavy die Exit ); my $string = join ' 0\4/f ', map( { rand $_ } 1 .. 60), map { $words[ rand @words ] } 1 .. 20; cmpthese (-2, { orig => sub { $string =~ /$pattern/i }, lc => sub { lc $string =~ /$pattern/ }, } );
|
|---|