http://qs1969.pair.com?node_id=655490


in reply to Not returning scalars(SV) to optimize and save memory?

use Benchmark can tell us what is fastest:
use strict; use constant FALSE => 1==0; use Benchmark qw(:all); cmpthese(1E7, { 'return;' => sub { return }, 'return FALSE;' => sub { return FALSE }, 'return 1==0;' => sub { return 1==0 }, 'implicit' => sub { }, 'implicit FALSE'=> sub { FALSE }, 'implicit 1==0' => sub { 1==0 }, });
Results:
Rate return FALSE; implicit FALSE return 1==0; i +mplicit return; implicit 1==0 return FALSE; 18281536/s -- -31% -54% + -63% -80% -92% implicit FALSE 26666667/s 46% -- -33% + -46% -71% -88% return 1==0; 40000000/s 119% 50% -- + -19% -56% -82% implicit 49261084/s 169% 85% 23% + -- -46% -77% return; 91743119/s 402% 244% 129% + 86% -- -58% implicit 1==0 217391304/s 1089% 715% 443% + 341% 137% --
It seems that sub { 1==0 } crushes all comers, 137% faster than its closest competitor, return; aka sub foo from your example. (My guess is that Perl has optimized the subroutine away.) sub bar aka return FALSE comes in dead last, but keep in mind that use constant has rolled FALSE into a closure, so you get overhead for subroutine calls when you use it (which is indicated by both uses of FALSE being in last place).

Not an examination of Perl's internal handling of SVs in subroutine returns, but a useful exploration of relative speed.