Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I think your benchmark is flawed. List::Util isn't as fast as you think it is. Go look at the source. And why are you looking at the speed of comparing two numbers?

If I find some time later, I'll elucidate on why your benchmark is flawed unless I'm preempted by some monk with more free time.

Update: Well, looks like everyone has done a good job saying the things that I first thought when I looked at your code. You're comparing apples to oranges. If you really want to benchmark "finding the max of 2 values", then you need to make sure that all of your subs do just that or if one needs to do more, then they all need to do the same extra stuff. In your subs, some copy the parameters, others don't; some use assignment, some don't; some use temp variables, some don't; etc.

Also, while you're using the same array for all benchmarks (which is good to keep the tests "the same"), in a real life situtation which number is larger will change with time, so to get numbers that are "more realistic", rather than using a random 2 element list, you should use 2 known lists. One where the first number is larger, and one where the second number is larger. Then either average the results or report them separately (depending on what you're trying to show)

As an aside, my initial reaction about List::Util is that "his numbers have to be wrong because I know List::Util is implemented in perl and uses the ternary op". It turns out that on the system I normally use (perl 5.8.6, List::Util 1.14) it's implemented in pure perl, but on another system I have (perl 5.8.0, List::Util 1.09_00) it's implemented in XS. In my benchmarks though, the straight ternary op is faster than List::Util::max even with the XS implementation. (I'd show my benchmarks, but having just read a thread on hop-discuss about how Benchmark.pm is broken I'm in the process of writing and using my own benchmarking routines, so take this result with a big grain of salt :-)


In reply to Re: assigning the maximum of two numbers by duff
in thread assigning the maximum of two numbers by bageler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (1)
As of 2024-04-18 23:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found