Re: efficient max() function from sort



Chas. Owens wrote:
On Wed, May 28, 2008 at 5:07 PM, Rob Dixon <rob.dixon@xxxxxxx> wrote:
snip
$max = (sort {$a <=> $b} @z)[-1];
snip

my $max = (sort { $b <=> $a } @z)[0];

is slightly faster than using [-1].

Or:

my ( $max ) = sort { $b <=> $a } @z;



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
.



Relevant Pages

  • Re: Valentines...alone again
    ... How about this year when i send him his card, ... And there could be all sorts of worries too. ... the two main alternatives, I reckon. ...
    (uk.people.support.depression)
  • Re: Distinct linear orderings on Z
    ... > defined by the philosophers. ... > been very weak and supposed all sorts of other definitions ... Yes, interestingly, even the common definitions, of 'motion', ...
    (sci.math)
  • Re: Paramo Fleeces
    ... to continue this deeply academic discussion: what sorts of sinphetyc ... shreddies are good ...
    (uk.rec.walking)
  • Re: Help - Im at wits end...
    ... >>However in some OS's (e.g Windows) the main routine may need to be ... >>different for the two sorts of files since the ...
    (sci.crypt)
  • Re: Sprint ST lifes span: Return to Invoice Insurance
    ... Dan White wrote: ... the small print will exclude all sorts ... they will only pay out X% if it ...
    (uk.rec.motorcycles)