The /o modifier isn't doing anything. Try running with and without it; when I did, there wasn't any difference. That modifier only affects patterns that have a variable interpolated in them, and your patterns don't.
The /g modifier seems to be the one that's making the difference, but I don't see why. I'd actually expect it to work the opposite way from what it does.
You might want to see also No More Meaningless Benchmarks! The operations involved are ridiculously fast, so I'm not sure how useful (or accurate) it is to compare them. Consider:
use Benchmark qw( cmpthese );
cmpthese( 10_000_000, { lower => sub { 'network' =~ /^network$/ },
upper => sub { 'networK' =~ /^networK$/ } } );
__END__
Rate lower upper
lower 3174603/s -- -9%
upper 3496503/s 10% --
Matching uppercase is faster than lowercase? Seriously?
I tried comparing literally the same subs, and there was still a 1% difference.
Adding an explicit scalar context brought the difference down a bit, but I'm not sure because the results aren't very consistent. In fact, I'd call them downright erratic.
All that being said, if someone can explain why a /g would make the pattern faster, I'd be very interested to hear. As it stands, I think there isn't a meaningful or consistent difference. |