in reply to Very Large Arrays
Ostensibly, there appears to be something going on here not obvious from the code snippet you posted.
A 43 million element array of 20-ish character strings should come in well below 3GB. And your Fisher-Yates implementation is in-place, so should cause no memory growth. Ie. You should be well within your machines capacity without swapping and your shuffle should be completing within seconds.
Is there a better way to do this, other than the iterative slicing he's doing?
There are a couple of small improvements you could make to your shuffle:
my $temp = $array->[ $i ]; $array->[ $i ] = $array->[ $j ]; $array->[ $j ] = $temp;
Swapping a value with itself does not invalidate the shuffle, and it is cheaper to do a single redundant swap than test 43 millions time to avoid it.
That said, the savings from the above will make little dent on the current processing time and are completely negated by your tracing code.
You need to look beyond the F-Y function for the cause of its slowness. Eg. Are you consuming large amounts of data outside of that subroutine that could be pushing you into swapping?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Very Large Arrays
by dave_the_m (Monsignor) on Feb 14, 2012 at 09:59 UTC | |
by BrowserUk (Patriarch) on Feb 14, 2012 at 13:32 UTC | |
by dave_the_m (Monsignor) on Feb 14, 2012 at 20:13 UTC | |
|
Re^2: Very Large Arrays
by Desade (Initiate) on Feb 16, 2012 at 00:36 UTC | |
by BrowserUk (Patriarch) on Feb 16, 2012 at 09:48 UTC | |
by Desade (Initiate) on Mar 16, 2012 at 16:12 UTC |