Using the benchmarking code above ...
timethese( 100, {
'better' => sub {
while ($mmap =~ m/(?:\A|\n)(.*$pat.*\n)/omg) {
}
},
'tye1' => sub {
while ($mmap =~ m/(?:\A|(?<=\n))(.*$pat.*\n)/omg) {
}
},
'tye2' => sub {
while ($mmap =~ m/(?:\A|(?<![^\n]))(.*$pat.*\n)/omg) {
}
},
})
__END__
Benchmark: timing 100 iterations of better, tye1, tye2...
better: 11 wallclock secs (10.61 usr + 0.00 sys = 10.61 CPU) @ 9
+.43/s (n=100)
tye1: 13 wallclock secs (12.37 usr + 0.00 sys = 12.37 CPU) @ 8
+.08/s (n=100)
tye2: 14 wallclock secs (14.16 usr + 0.00 sys = 14.16 CPU) @ 7
+.06/s (n=100)
I have no idea how to figure out why these numbers are the way they are. The only thing I can think of is that the lookaround assertion takes more time than the actual character check. *shrugs*
Being right, does not endow the right to be rude; politeness costs nothing. Being unknowing, is not the same as being stupid. Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence. Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.
|