in reply to assigning the maximum of two numbers

I too, have issues with your benchmarks. In the top you are creating a temporary array, and using shift/pop, which just isn't needed. @_, $a[0], $a-1 would suffice and be faster. Assignmax2..4 aren't recursive so they don't even remotely do the same thing Assignmax, or Assignmax5 oddly you don't push/pop/shift/unshift on the, nor do you create a temporary array. This is also probably a poor area to optimize, assuming your not mutating the entire list.

I would imagine that List::Util would be atleast as fast as the fastest all perl solution. Logic would dictate that there is chance List::Util is optimized C (without looking at it) and in the event it isn't than someone has already done all the work your doing and figured out the fastest way to get a max().


Evan Carroll
www.EvanCarroll.com
  • Comment on Re: assigning the maximum of two numbers

Replies are listed 'Best First'.
Re^2: assigning the maximum of two numbers
by GrandFather (Saint) on Nov 02, 2005 at 23:31 UTC

    Don't underestimate all Perl solutions. See some of the later benchmarks where the use of the ternary operator has been improved!

    For an arbitary number of values the List::Util approach is very likely to be fastest, and surely the fastest to code. For the two element special case the ternary operator wins hands down.


    Perl is Huffman encoded by design.