davido:~/scripts$ perlbrew exec --with perl-5.10.1 perl mytest.pl
Perl version: 5.010001
Rate retn bare
retn 6849315/s -- -8%
bare 7462687/s 9% --
(25000000, 25000000)
davido:~/scripts$ perlbrew exec --with perl-5.28.0 perl mytest.pl
Perl version: 5.028000
Rate bare retn
bare 10729614/s -- -3%
retn 11013216/s 3% --
(25000000, 25000000)
I mean I do see a difference, but other optimizations between Perl 5.10 and Perl 5.28 seem to be far more significant (probably the integer optimization).
Here is the sample code:
use strict;
use warnings;
use Benchmark qw(cmpthese);
my $x;
my $y;
sub bare { ++$x; $x }
sub retn { ++$y; return $y }
print "Perl version: $]\n\n";
cmpthese(25_000_000, {
bare => sub {my $t = bare()},
retn => sub {my $t = retn()},
});
print "\n($x, $y)\n";
The reason for the double sub call is to assure that the return value is being obtained, and not discarded due to context. So we do have the double-call overhead, but it's the same overhead for both sides of the test.
Anyway, where there had been a 9% difference in favor of bare returns in 5.10, there's now a statistically insignificant 3% difference that seems to go either direction.
|