I wonder what it takes to trigger that optimization.

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.


Dave


In reply to Re^4: Proxying (almost) all methods in a class for mass memoization by davido
in thread Proxying (almost) all methods in a class for mass memoization by Tommy

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.