C:\test>786728-1.pl
Rate three one two
three 95432/s -- -13% -35%
one 110191/s 15% -- -25%
two 146082/s 53% 33% --
####
C:\test>786728-2.pl
Rate one two three
one 6935150/s -- -0% -6%
two 6965018/s 0% -- -5%
three 7345874/s 6% 5% --
####
use strict;
use warnings;
use Benchmark;
our @strings = qw(exception:tex exception:mex asdf tex:exception:mex);
Benchmark::cmpthese( -5, {
'one' => q[ my @filtered = grep { /exception:(?!tex)/} @unfiltered; ],
'two' => q[ my @filtered = grep { /exception/ && !/tex/ } @unfiltered; ],
'three' => q[ my @filtered = grep { /exception:/g && !/\Gtex/ } @unfiltered; ],
});