Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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

by umasuresh (Hermit)
on Feb 24, 2011 at 21:01 UTC ( [id://890060]=note: print w/replies, xml ) Need Help??


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

Ikegami,
Thanks for your suggestion. I am dereferencing the array indices before accessing the global array. May be my question should have been which one of these is faster: dereferencing an array or a scalar.
Uma
  • Comment on Re^2: Pass an array reference or array indices to a subroutine?

Replies are listed 'Best First'.
Re^3: Pass an array reference or array indices to a subroutine?
by chromatic (Archbishop) on Feb 24, 2011 at 21:38 UTC
    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.

      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.

Re^3: Pass an array reference or array indices to a subroutine?
by ikegami (Patriarch) on Feb 24, 2011 at 21:06 UTC

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

    There's no difference.

    And that shouldn't be the question at all. There's no point of comparing things that aren't equivalent.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://890060]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-25 14:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found