Unfortunately, I don't think you'll get any great gains because of how arguments work. @_ will still have to be created for the inlined function, and I imagine that's where most of the time is spent.

Reults of my fairest approximation:

Rate copy nocopy inline_copy inlin +e_nocopy copy 534208/s -- -9% -13% + -23% nocopy 587704/s 10% -- -4% + -16% inline_copy 610942/s 14% 4% -- + -12% inline_nocopy 697762/s 31% 19% 14% + --
use strict; use warnings; use Benchmark qw( cmpthese ); sub attrib_copy { my ($self) = @_; $self->{attrib} } sub attrib_nocopy { $_[0]->{attrib} } our $self = bless({ attrib => 'some_value' }); my %tests = ( copy => 'my $x = do { local @_ = $self; &main::attrib_cop +y };', nocopy => 'my $x = do { local @_ = $self; &main::attrib_noc +opy };', inline_copy => 'my $x = do { local @_ = $self; my ($self) = @_; +$self->{attrib} };', inline_nocopy => 'my $x = do { local @_ = $self; +$_[0]->{attrib} };', ); $_ = 'use strict; use warnings; our $self; ' . $_ for values %tests; cmpthese(-3, \%tests);

See how you can almost get the same benefit from not copying the @_ into local vars?


In reply to Re: Perl keyword like the C/C++ keyword 'inline' by ikegami
in thread Perl keyword like the C/C++ keyword 'inline' by sadarax

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.