Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Speed differences between Union, Tally and DeleteDuplicates

  • To: mathgroup at smc.vnet.net
  • Subject: [mg97054] Speed differences between Union, Tally and DeleteDuplicates
  • From: Yves Klett <yves.klett at googlemail.com>
  • Date: Wed, 4 Mar 2009 07:10:58 -0500 (EST)

Dear group,

I just noticed some differences in speed between Union, Tally and
DeleteDuplicates.

Consider 3D-points that appear multiple times in a coordinate list. I'd
like to remove duplicates without changing the order (pre-6: the good
ole UnsortedUnion). Now DeleteDuplicates and Tally can do this, and for
lists only containing numbers DeleteDuplicates is very fast - but for
coordinate tuples it is much slower than Tally (and Union, although the
sorted result differs of course)

(*Example*)
n = 500;
don = 10;
pts = RandomReal[{-1, 1}, {n, 3}];
rpts = RandomSample[Join[pts, pts], 2 n];
union = Do[Union[rpts], {don}] // Timing;
tally = Do[Tally[pts][[All, 1]], {don}] // Timing;
deleteduplicates = Do[DeleteDuplicates[pts], {don}] // Timing;

Tally[pts][[All, 1]] == DeleteDuplicates[pts]
{union, tally, deleteduplicates}
(*EOF*)

True
{{0., Null}, {0.016, Null}, {0.484, Null}}


For me this is important information because the online documentation
shows an example that is much faster than Union/Tally, but that does not
seem to be the case for more complex lists...

So I guess I=C2=B4ll go back to Tally - anyway suggestions to optimized use
of DeleteDuplicates or others are welcome.

Regards,

Yves



  • Prev by Date: Re: Experimental Mathematica debugger
  • Next by Date: Re: Head logic
  • Previous by thread: Re: Problems in writing into a sequential filename
  • Next by thread: How to "vectorize" code