cmpthese( -1, { 'a' => GRT($s), 'b' => ST($s) } ) ;
This calls both GRT and ST just once, and uses their output as the code to eval and benchmark. That's not what we want. Instead, we need
cmpthese(-3, {
grt => sub { GRT($s) },
st => sub { ST($s) }
});
It still seems that ST is much faster:
Rate grt st
grt 2.75/s -- -76%
st 11.6/s 320% --
But, notice the regex is different when splitting the string:
split m{(?<!\A)(?=>>>)}, $s # GRT
split (/^(?=>>> )/m, $s) # ST
So, let's add a test to verify the results stay correct
use Test::More tests => 1;
is GRT($s), ST($s), 'same';
and we can use the simpler regex from ST in GRT. Fortunately, the test remains successful, and the results are now different:
1..1
ok 1 - same
Rate st grt
st 11.7/s -- -3%
grt 12.1/s 3% --
An insignificant difference, but at least ST doesn't seem to be much faster now.
Benchmarking and optimisation are hard.
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
|