The Benchmark module is a big help with this sort of thing.

What the Schwartzian Transform does is reduce the overall number of calls to the function that computes the value of your item. Your sort is going to do roughly (n * log n) comparisons where n is the number of items in your list. If the function that computes the value of the list item is significantly more expensive than a simple comparison you want to reduce the number of calls to that more expensive function.

The map at the end of the Schwartzian transform only runs the function once for each element of the list. Of course you incur some overhead in building an arrayref, and looping again at the end, but for lists with many items reducing the number of computations can save a lot of cycles. You'll see very different results based on how expensive it is to compute the sort value.


In reply to Re: Benchmark Schwartzian Transform by thunders
in thread Benchmark Schwartzian Transform by Anonymous Monk

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.