in reply to Re^4: pop sort strangeness
in thread pop sort strangeness
So in all cases, using the built in List::Util proceedure was quite a bit more than twice as fast as either of the others. And it's also much simpler to use, so it seems like something of a no-brainer to me.#!/usr/bin/perl use strict; use warnings; use List::Util qw/ maxstr /; use Benchmark qw/ cmpthese /; my @vals = reverse "a" .. "daa"; cmpthese( -10, { sorting => sub {my $max = pop @{[sort @vals]}}, iterating => sub { my $max = $vals[0]; $max = ( $_ gt $max ) ? $_ : $max foreach @vals; }, list_util => sub {my $max = maxstr @vals} }); __END__ Rate sorting iterating list_utils sorting 0.659/s -- -42% -82% iterating 1.13/s 72% -- -69% list_util 3.67/s 458% 224% -- Rate sorting iterating list_utils sorting 537/s -- -32% -80% iterating 789/s 47% -- -70% list_util 2661/s 395% 237% -- Rate sorting iterating list_utils sorting 50180/s -- -25% -78% iterating 66991/s 34% -- -70% list_utils 225804/s 350% 237% --
|
|---|