Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Just as quickly? Looks like (surprisingly, to me at least) ~9-10% faster on average.

use Benchmark qw( timethese cmpthese ); use List::Util qw( shuffle ); for my $max (qw( 100 200 500 1000 2000 5000 )) { print "results for $max elems\n"; my @big_list = shuffle 1 .. $max; cmpthese( -1, { plain_sort => sub { my @local = sort { $b <=> $a } @big_list; }, reversed => sub { my @local = reverse sort { $a <=> $b } @big_list; }, } ); print "\n"; } exit 0; __END__ results for 100 elems               Rate plain_sort   reversed plain_sort 46849/s         --        -8% reversed   50717/s         8%         -- results for 200 elems               Rate plain_sort   reversed plain_sort 20676/s         --       -12% reversed   23424/s        13%         -- results for 500 elems              Rate plain_sort   reversed plain_sort 7657/s         --        -9% reversed   8374/s         9%         -- results for 1000 elems              Rate plain_sort   reversed plain_sort 3490/s         --        -8% reversed   3794/s         9%         -- results for 2000 elems              Rate plain_sort   reversed plain_sort 1599/s         --        -9% reversed   1756/s        10%         -- results for 5000 elems             Rate plain_sort   reversed plain_sort 553/s         --       -10% reversed   613/s        11%         --

This space reserved for the update when someone points out my obvious benchmark fau pas . . . :)

The cake is a lie.
The cake is a lie.
The cake is a lie.


In reply to Re^3: Predefined Sort by Fletch
in thread Predefined Sort by k_grdn

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (8)
    As of 2014-12-22 02:12 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (110 votes), past polls