in reply to Re^2: Pass an array reference or array indices to a subroutine?
in thread Pass an array reference or array indices to a subroutine?

May be my question should have been which one of these is faster: dereferencing an array or a scalar.

They're about the same; almost irrelevant in any real program.

Accessing a lexical is faster than accessing a global, though the speed difference there is also almost always irrelevant.

  • Comment on Re^3: Pass an array reference or array indices to a subroutine?

Replies are listed 'Best First'.
Re^4: Pass an array reference or array indices to a subroutine?
by ikegami (Patriarch) on Feb 24, 2011 at 22:13 UTC

    They're about the same; almost irrelevant in any real program.

    I propose that they're exactly the same.

    $ perl -MO=Concise,-exec -e'$$ref' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v:{ 3 <$> gvsv(*ref) s 4 <1> rv2sv vK/1 5 <@> leave[1 ref] vKP/REFC -e syntax OK $ perl -MO=Concise,-exec -e'@$ref' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v:{ 3 <$> gvsv(*ref) s 4 <1> rv2av[t1] vK/1 5 <@> leave[1 ref] vKP/REFC -e syntax OK

    The normal case of rv2sv boils down to a couple of checks plus

    sv = SvRV(sv);

    The normal case of rv2av boils down to a couple of checks plus

    sv = SvRV(sv);

    So any difference in performance is not intrinsic to the operation.