in reply to Re^2: named sub, subref and magic goto speed
in thread named sub, subref and magic goto speed

I'm not sure what you're asking, but goto &$ref is no faster than foo(), which is in line with the linked node.

use strict; use warnings; use Benchmark qw( cmpthese ); sub foo { @_ } my $ref = \&foo; cmpthese(-2, { refcall => sub { @_=(1); $ref->(@_) }, named => sub { @_=(1); foo(@_) }, g_scalar => sub { @_=(1); goto $ref }, g_amp => sub { @_=(1); goto &$ref }, });

outputs

Rate named refcall g_amp g_scalar named 811837/s -- -1% -3% -26% refcall 820126/s 1% -- -2% -25% g_amp 834174/s 3% 2% -- -24% g_scalar 1099304/s 35% 34% 32% --

Replies are listed 'Best First'.
Re^4: named sub, subref and magic goto speed
by Limbic~Region (Chancellor) on Dec 14, 2006 at 16:50 UTC
    ikegami,

    ysth said:

    WRT the stack frame, refcall and named have to build a new stack frame and put the contents of @_ on the stack; that's heavy lifting.

    To me, that implied this wasn't the case for goto $ref; which is really you say is goto &$ref;. I was asking for clarification on that point.

    Update: See <del> and <ins> for minor wording modification.

    Cheers - L~R

      ( ah, I don't know. ) However, you can't say that goto $ref is really goto &$ref. My benchmarks show they are quite different.
        ikegami,
        You have updated your node without noting it as such. The content of your original node to which my reply applies to was:

        My benchmarks show that goto $ref is quite different from goto &$ref.

        First, I want to make it clear that my question has nothing to do with speed or benchmarks. My question is specifically regarding to ysth's implied assertion that goto &$ref; does not have to build a stack frame.

        Of course, this assumes that goto $ref; truly is the same as goto &$ref; which you yourself say:

        The docs say a label is expected, but if a code ref is provided, goto $ref is treated as goto &$ref.

        Since your benchmarks indicate that this isn't the case, perhaps perl is doing something special under the covers and you should revise your statement. My original question was regarding stack frames only, but at this point I am also interested in knowing why goto $ref; is behaving as if it were goto &$ref; but performs much better.

        Cheers - L~R