in reply to Very Large Arrays

Shuffling an array is one of those thinks that can be done much more efficiently in C/XS than in Perl.

I have just uploaded to CPAN Array::Shuffle, that is one or two orders of magnitude faster than List::Util::shuffle or your hand-crafted shuffle implementation in Perl.

It's memory usage is O(1).

(List::Util::shuffle is also implemented in C, but it has the wrong interface from a performance point of view)

Replies are listed 'Best First'.
Re^2: Very Large Arrays
by Anonymous Monk on Sep 30, 2024 at 06:19 UTC
    Just tried the included benchmark script with perl 5.40 on macOS and shuffle_array fails every time with bus error or segfault. And shuffle_huge_array fails every time claiming the array has attached magic.
Re^2: Very Large Arrays
by Anonymous Monk on Feb 17, 2012 at 17:02 UTC
    As List::Util is available separately on CPAN, why didn't you submit a patch to that, so everybody benefits?
      Because Array::Shuffle functions do the operations in-place for better performance and so they do not really fit inside List::Util, and also because List::Util is famous for refusing to include additional functions (that's why we also have List::MoreUtil).

      Besides that, because I also wanted to play with different shuffle algorithms, and so creating a new specialiced module made sense to me.