Here are my results, first with your "a" .. "daaa", and then with a much smaller dataset ("a".."daa", only 2731 values), and finally with just "a" .. "aa" (27 values).
#!/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% --
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.

In reply to Re^5: pop sort strangeness by Eimi Metamorphoumai
in thread pop sort strangeness by Brovnik

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.