in reply to Re^2: Remove Duplicates from Array
in thread Remove Duplicates from Array
And List::MoreUtils::uniq can be faster as it tries to load a library to implement its functionality via DynaLoader. If that fails it implements a plain perl way.
In my test (linux, perl 5.8.8 List::MoreUtils 0.21) the original List::MoreUtils::uniq is about 400% faster than my perl implementation.
If I rename the library, so List::MoreUtils must rely on its perl implementation, my solution is about 20% - 25% faster.
I don't want to argue against List::MoreUtils; but now I wonder about these two (perl) solutions:
# presented in perlfaq4 - How can I remove duplicate elements from a l +ist or array? sub my_uniq { my %h; grep { !$h{$_}++ } @_; } # vs. # List::MoreUtils::uniq sub LM_uniq { my %h; map { $h{$_}++ == 0 ? $_ : () } @_; }
I can't recognize an advantage in the usage of map and the ternary operator.
edit: text refined
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Remove Duplicates from Array
by mpeever (Friar) on Nov 01, 2008 at 17:10 UTC | |
|
Re^4: Remove Duplicates from Array
by JadeNB (Chaplain) on Nov 02, 2008 at 20:21 UTC | |
by mpeever (Friar) on Nov 03, 2008 at 00:18 UTC | |
by JadeNB (Chaplain) on Nov 03, 2008 at 15:22 UTC |