Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: assigning the maximum of two numbers

by EvanCarroll (Chaplain)
on Nov 02, 2005 at 23:08 UTC ( [id://505170]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-19 16:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found