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

Comment on

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

Just to clarify Pustular Postulant, the OP must have called the functions in a void or scalar context. sort is optimized to do nothing in that situation, so the functions naive and orcish return instantly. Read more for confirmation of Pustular Postulant's results and confirmation that running the sorts in scalar context give results similar to those of the OP.

my @unsorted = sort map { "foo$_.tla" } 0..999; Benchmark::cmpthese(5000, { naive => sub { my @a = naive @unsorted; }, orcish => sub { my @a = orcish @unsorted; }, schwartzian => sub { my @a = schwartzian @unsorted; }, guttros => sub { my @a = guttros @unsorted; }, });

gives me

Rate naive orcish schwartzian guttros naive 48.3/s -- -34% -46% -60% orcish 73.1/s 51% -- -19% -40% schwartzian 90.1/s 86% 23% -- -26% guttros 122/s 152% 67% 35% --

while

my @unsorted = sort map { "foo$_.tla" } 0..999; Benchmark::cmpthese(5000, { naive => sub { scalar naive @unsorted; }, orcish => sub { scalar orcish @unsorted; }, schwartzian => sub { scalar schwartzian @unsorted; }, guttros => sub { scalar guttros @unsorted; }, });

gives me

(warning: too few iterations for a reliable count) (warning: too few iterations for a reliable count) Rate schwartzian guttros orcish naive schwartzian 107/s -- -26% -100% -100% guttros 144/s 35% -- -100% -100% orcish 106383/s 99666% 73834% -- -0% naive 106383/s 99666% 73834% 0% --

That's why it's important to show one's work :)


In reply to Re^2: Choosing the right sort (Or: WUDsamatter?) by ikegami
in thread Choosing the right sort (Or: WUDsamatter?) by friedo

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 meditating upon the Monastery: (6)
    As of 2014-04-20 09:18 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (485 votes), past polls