Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Comment on

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

If you accept the principle that code in modules is destined to be reused in lots of situations, including performance critical ones, and should therefore do it's utmost to be as efficient as the author is comfortable maintaining, then List::Util's use of aliasing to sqeeze a little more performance seems entirely reasonable.

I'm not saying it isn't. (Well, except that some comments for the benefit of the occasional peeping Tom would have been nice.) In fact I'm amazed, because I wouldn't have expected it to be that efficient. The question still is: how does one come up with such code? I suspect that one critical difference is that the naive implementation, due to its de facto shuffling of an array in place, does so by taking two slices, and assigning to one of them. While L::U's doesn't really swap, and the overhead of dereferencing weights less. BTW, testing with

for my $i (map 10**$_, 1..4) { cmpthese -30, { map { $_ => "$_ 1..$i" } qw/naive buk/ }; }

one seems to get a slowly decreasing trend:

Rate naive buk naive 49811/s -- -37% buk 79547/s 60% -- Rate naive buk naive 4751/s -- -33% buk 7112/s 50% -- Rate naive buk naive 479/s -- -29% buk 677/s 41% -- Rate naive buk naive 46.9/s -- -27% buk 64.6/s 38% --

That said, they missed a trick. Using a block form map creates a additional level of scope that they aren't using and slows performance.

They can squeeze another 30%, and almost 50% over the 'naive' implementation, by avoiding it


In reply to Re^2: About List::Util's pure Perl shuffle() by blazar
in thread About List::Util's pure Perl shuffle() by blazar

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, 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
  • 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (8)
    As of 2018-05-24 20:03 GMT
    Find Nodes?
      Voting Booth?