in reply to Re^3: More efficient way to get uniq list elements from list of lists
in thread More efficient way to get uniq list elements from list of lists
This is not only more compact, it's also a different, slower algorithm
To my eye it looks like the same algorithm as pg's solution, just rolled up into a single statement; what strikes you as different about it?
And running your benchmark script with a few additions indicates that it's actually faster than any of the alternatives you had included:
ewijaya 37879/s ewijaya_longrand 38610/s pg_longrand 96154/s pg 100000/s aighearach 103093/s aighearach_longrand 105263/s scooterm 107527/s scooterm_longrand 114943/s simonm 117647/s simonm_longrand 126582/s simonm2 131579/s simonm2_longrand 144928/s
I'm not sure why the results differ from those you showed; FWIW, I'm running 5.6.0 on darwin.
Here're the two subs I tested:
sub simonm { sort keys %{ { map { $_ => undef } map @$_, @_ } } } sub simonm2 { my ( %unique ); @unique{ map @$_, @_ } = (); sort keys %unique }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: More efficient way to get uniq list elements from list of lists
by Aighearach (Initiate) on Nov 11, 2004 at 23:01 UTC |