in reply to assigning the maximum of two numbers
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 :-)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: assigning the maximum of two numbers
by bageler (Hermit) on Nov 02, 2005 at 22:57 UTC | |
by duff (Parson) on Nov 03, 2005 at 01:55 UTC |