in reply to <=> vs cmp
Furthermore, your results don't give a huge difference.
There isn't much that can be said based on your posting.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: = vs cmp
by Jasper (Chaplain) on May 27, 2002 at 13:39 UTC | |
yeah, sorry.. Now deleted the code, so I can't post exactly what I benchmarked, but it was just an array of 200 or so 4 digit integers. The code was as basic as I could make it. something like: I was just surprised that sorting using cmp was not much slower than <=>; for .. I realise now that I just hadn't thought about it too much (heavy weekend), and if I had, I probably wouldn't have had a preconcieved idea about the relative speeds..(fiddling with the sizes of the integers, making them 1-16 digits long doesn't have much effect on the relative (or actual) speed of the sorts, either, btw). I shall just use sort on its lonesome, I think. | [reply] [d/l] |
by joealba (Hermit) on May 27, 2002 at 14:26 UTC | |
PRINTS: Looks like a pretty even race to me! | [reply] [d/l] [select] |
by Anonymous Monk on May 28, 2002 at 11:33 UTC | |
One should realize that Benchmark calls your function in void context. And sorting in void context is optimized to not do the sorting. So, you haven't benchmark anything. Benchmarking is an art, and you shouldn't test something with one size of data and draw conclusions. Here's a better benchmark:
Name "main::array" used only once: possible typo at ./sort_bench.pl line 9. Benchmark: running 10 <=>, 10 cmp, each for at least 3 CPU seconds... 10 <=>: 4 wallclock secs ( 3.13 usr + 0.01 sys = 3.14 CPU) @ 45414.01/s (n=142600) 10 cmp: 3 wallclock secs ( 3.01 usr + 0.00 sys = 3.01 CPU) @ 44175.08/s (n=132967) Benchmark: running 100 <=>, 100 cmp, each for at least 3 CPU seconds... 100 <=>: 3 wallclock secs ( 3.23 usr + 0.01 sys = 3.24 CPU) @ 4453.70/s (n=14430) 100 cmp: 3 wallclock secs ( 3.23 usr + 0.00 sys = 3.23 CPU) @ 4095.67/s (n=13229) Benchmark: running 1000 <=>, 1000 cmp, each for at least 3 CPU seconds... 1000 <=>: 3 wallclock secs ( 3.22 usr + 0.01 sys = 3.23 CPU) @ 324.77/s (n=1049) 1000 cmp: 3 wallclock secs ( 3.26 usr + 0.00 sys = 3.26 CPU) @ 292.64/s (n=954) Benchmark: running 10000 <=>, 10000 cmp, each for at least 3 CPU seconds... 10000 <=>: 3 wallclock secs ( 3.09 usr + 0.01 sys = 3.10 CPU) @ 17.74/s (n=55) 10000 cmp: 3 wallclock secs ( 3.08 usr + 0.00 sys = 3.08 CPU) @ 13.96/s (n=43) Benchmark: running 100000 <=>, 100000 cmp, each for at least 3 CPU seconds... 100000 <=>: 4 wallclock secs ( 3.42 usr + 0.01 sys = 3.43 CPU) @ 1.17/s (n=4) 100000 cmp: 3 wallclock secs ( 3.30 usr + 0.01 sys = 3.31 CPU) @ 0.91/s (n=3) (warning: too few iterations for a reliable count) | [reply] [d/l] |