"be consistent" | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
In a recent discussion (link @ GG) in ctt, PerlTeX was mentioned (and I'm also mentioning it here because it is not that widely known and IMHO it would deserve being) in relation to shuffling, at which point in reply to a posted piece of code I wrote about the perldoc -q shuffle FAQ entry, talking in particular about both Fisher-Yates and List::Util's shuffle(). Now, I happened to check the source code for the latter module, and since it has pure Perl code for the given function, I noticed that in particular it is as follows:
Now, at first sight it is a nice piece of Obfu, ain't it? Well, then if you look at it, it's easy to see how it works and in particular that it is still Fisher-Yates. But of course you have to think about it for a while... and I wondered why it is like that... To be fair, I think that taking references in the first place is to avoid duplicating data in memory that could be heavy in memory usage... but then I also thought that all that playing with references would impose a performance penalty and -for once- I suppose that performance does matter. So I tried the following Benchmark, comparing a naive and fairly readable implementation of the algorithm with List::Util's:
The results are as follows:
So that pretty much may answer my question as to why the sub is implemented like that... but then this raises the question as to how could one come up with such an idea, because I'm sure I wouldn't have... Any comments? In reply to About List::Util's pure Perl shuffle() by blazar
|
|