in reply to Re^8: Regex match at the beginning or end of string
in thread Regex match at the beginning or end of string
Ah well. If we're allowed to cheat then the difference moves into the realms of run to run variability :)
use strict; use warnings; use 5.010; use Benchmark qw[ cmpthese ]; use List::Util qw[ shuffle ]; our @terms = qw[ the quick brown fox jumps over the lazy dog ]; our $re = join'', map "(?=^.*$_)", @terms; #$re = qr/$re/; our @lines = map join( ' ', shuffle @terms), 1 .. 100; push @lines, ( 'every good boy deserves food' ) x 100; my $line = join '&&', map {"/$_/"} @terms; our( $a, $b, $c, $d) = (0) x 4; cmpthese -1, { a=>q[ /$re/ and ++$a for @lines; ], d=>qq[ /$re/ and ++\$d for \@lines; ], b=>q[ for my $str ( @lines ) { !grep( $str !~ /$_/, @terms) and ++ +$b; } ], c=>qq [$line && ++\$c for \@lines;], }; say "$a:$b:$c:$d"; __END__ C:\test>junk48 Rate b a d c b 82.7/s -- -97% -97% -99% a 2657/s 3112% -- -3% -56% d 2748/s 3222% 3% -- -54% c 5982/s 7132% 125% 118% -- 388200:12000:829800:389700
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^10: Regex match at the beginning or end of string
by JavaFan (Canon) on Feb 20, 2011 at 22:07 UTC |