MathGroup Archive 2010

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

Search the Archive

Re: List of multiple elements

  • To: mathgroup at smc.vnet.net
  • Subject: [mg112114] Re: List of multiple elements
  • From: Ray Koopman <koopman at sfu.ca>
  • Date: Tue, 31 Aug 2010 04:16:28 -0400 (EDT)
  • References: <i5d019$bs8$1@smc.vnet.net> <i5g0hu$gos$1@smc.vnet.net>

On Aug 30, 3:18 am, Ray Koopman <koopman at sfu.ca> wrote:
>
> dupels2 is a faster version of DuplicateElements:
>
> dupels2[v_List] := Module[{f,dups={}},
> f[n_] := (f[n] := (dups = {dups,n})); f/@v; Flatten@dups]

dupels1 is twice as fast as dupels2.

dupels1[v_List] :=  Module[{f}, f[x_] := ((f[x] = x); {});
                                Flatten[f/@v]]

{m,n} = {50,1*^4}
Timing[w = Table[Random[Integer,{1,m}],{n}]; Do[Null,{1*^7}]];
First@AbsoluteTiming[t1 = dupels1[w];]
First@AbsoluteTiming[t2 = dupels2[w];]
t1 === t2

{50,10000}
0.030357 Second
0.060681 Second
True


  • Prev by Date: Re: Working with Log
  • Next by Date: Re: How avoid .nb in palette title bar?
  • Previous by thread: Re: List of multiple elements
  • Next by thread: Re: List of multiple elements