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.


In reply to Re: Not returning scalars(SV) to optimize and save memory? by gamache
in thread Not returning scalars(SV) to optimize and save memory? by Withigo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.