MathGroup Archive 2008

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

Search the Archive

Re: List concatenation speed

  • To: mathgroup at smc.vnet.net
  • Subject: [mg87649] Re: [mg87571] List concatenation speed
  • From: János <janos.lobb at yale.edu>
  • Date: Tue, 15 Apr 2008 05:48:55 -0400 (EDT)
  • References: <200804130732.DAA11515@smc.vnet.net>

On Apr 13, 2008, at 3:32 AM, carlos at Colorado.EDU wrote:
> I am building mesh plots that require concatenation of thousands of
> Graphics objects into one list for Show[].  This is done by appending
> objects as they are created, and there are several ways to do that.
> Tested 3 of them for speed using a simple object:
>
>      p=Table[x,{50}]; n=10000;
>      ClearAll[poly]; poly={};
>      Print[Timing[Do[AppendTo[poly,p],{i,1,n}]]];
>      ClearAll[poly]; poly={};
>      Print[Timing[Do[poly=Append[poly,p],{i,1,n}]]];
>      ClearAll[poly]; poly={};
>      Print[Timing[Do[poly=Join[poly,{p}],{i,1,n}]]];
>
> {5.8395 Second,Null}
> {5.7206 Second,Null}
> {6.29728 Second,Null}
>
> Tests were run on version 5.2 on a G5 desktop Mac. I expected Join to
> win,
> but it didnt.  Is there a faster way?

Here is a newbie approach:
> In[14]:=
> Timing[Reap[i = 1;
>      While[i <= n, Sow[p];
>        i++; ]]; ]
> Out[14]=
> {0.11680799999999891*Second,
>   Null}


For comparison:
In[6]:=Timing[Do[AppendTo[poly, p],    {i, 1, n}]]
Out[6]={6.827495*Second, Null}

J=E1nos

> In[24]:=
> $Version
> Out[24]=
> "5.2 for Mac OS X (64 bit) \
> (June 20, 2005)"


  • Prev by Date: Re: A Problem with Simplify
  • Next by Date: Re: Manipulate on the web
  • Previous by thread: Re: List concatenation speed
  • Next by thread: Re: List concatenation speed