Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-19 03:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found