in reply to Re: = vs cmp
in thread <=> vs cmp
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).use Benchmark; my @array = (6252,8278, ...array of 200 4 digit integers...; timethese(0, { sorty => \&sorty, space => \&spaceship, comp => \&comp }); sub sorty { return sort @array } sub comp { return sort {$a cmp $b} @array } sub spaceship { return sort {$a <=> $b} @array } ## gives: Benchmark: running comp, sorty, space, each for at least 3 CPU seconds +... comp: 2 wallclock secs ( 3.05 usr + 0.02 sys = 3.07CPU) @ 617 +076.87/s (n=1894426) sorty: 1 wallclock secs ( 3.06 usr + -0.00 sys = 3.06CPU) @ 650 +267.65/s (n=1989819) space: 3 wallclock secs ( 3.38 usr + 0.02 sys = 3.40CPU) @ 590 +187.65/s (n=2006638)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: = vs cmp
by joealba (Hermit) on May 27, 2002 at 14:26 UTC | |
|
Re: = vs cmp
by Anonymous Monk on May 28, 2002 at 11:33 UTC |