Re: efficient max() function from sort
- From: rob.dixon@xxxxxxx (Rob Dixon)
- Date: Wed, 28 May 2008 23:05:41 +0100
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].
You should only use this form if performance matters and you know that
@z is smaller than 250 items (over 250 items List::Util::max is
faster).
But in general the bottleneck is the programmer. Whether we are writing code
purely for ourselves or for commercial purposes it is always more efficient in
every sense to write something that we recognize rather than something that will
process faster.
use List::Util qw/max/;
$max = max @z;
is always the best option, unless very few people are writing code for many
millions of others to use, or the circumstances are otherwise extraordinary.
Rob
.
- References:
- efficient max() function from sort
- From: Ramprasad A Padmanabhan
- Re: efficient max() function from sort
- From: Rob Dixon
- Re: efficient max() function from sort
- From: Chas. Owens
- efficient max() function from sort
- Prev by Date: Re: efficient max() function from sort
- Next by Date: Re: assign default value to variables I assign from split
- Previous by thread: Re: efficient max() function from sort
- Next by thread: Re: efficient max() function from sort
- Index(es):
Relevant Pages
|