in reply to Re^2: mem usage
in thread mem usage
You can trim your shuffle a little by omitting the line: next if $i==$j;.
Swapping an item with itself doesn't affect the algorithm's fairness, and doing it once costs less, than testing n times and avoiding it once.
And you save a little more by avoiding the list assignment:
my $tmp = $array[ $i ]; $array[ $i ] = $array[ $j ]; $array[ $j ] = $tmp;
Doesn't look as nice though.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: mem usage
by ikegami (Patriarch) on May 26, 2010 at 19:46 UTC | |
Re^4: mem usage
by halfcountplus (Hermit) on May 26, 2010 at 19:36 UTC |