http://www.perlmonks.org?node_id=405486


in reply to Re^2: How to pass two lists to a sub?
in thread How to pass two lists to a sub?

Personal coding preferences aside, I did consider something along the lines you have here but decided against it for two reasons.

  1. YAFZ asked specifically for arrays: "All I need is a simple construct in which I'll have two correct @l1 and @l2 at the end."
  2. Some benchmarking I carried a few months ago indicated that evaluating $array[$i] was faster than evaluating $arrayref->[$i]. (As one might expect given the additional dereference operation.)

(Minor point: You have $arrayref->[i] in a number of places.)

Regards,

PN5

Replies are listed 'Best First'.
Re^4: How to pass two lists to a sub?
by revdiablo (Prior) on Nov 05, 2004 at 19:25 UTC
    Some benchmarking I carried a few months ago indicated that evaluating $array[$i] was faster than evaluating $arrayref->[$i].

    I am not trying to say your benchmark is wrong, and I don't want to say there are no applications where this would make a difference, but using this as a general rule of thumb does not strike me as a good idea. I would be very surprised if most, or even many, applications would benefit from this kind of nano-optimization.

    More generally, this type of benchmarking is almost always pointless. Using it in isolation to determine the semantics of your code is, frankly, silly. There may be cases where these types of small optimizations add up to real savings, but those are the exception, not the rule. Contorting your code for the exception, without knowing if you are truly hitting that exception, is a waste of time and effort.