Re: Another AppendTo replacement problem
- To: mathgroup at smc.vnet.net
- Subject: [mg118290] Re: Another AppendTo replacement problem
- From: Ray Koopman <koopman at sfu.ca>
- Date: Wed, 20 Apr 2011 04:28:44 -0400 (EDT)
- References: <ioek97$mvg$1@smc.vnet.net>
On Apr 18, 6:50 am, Bill Rowe <readn... at sbcglobal.net> wrote: > The results I get indicate simply using nested lists then using > Partition to reconstruct the array appropriately is faster. That is: > > In[1]:= Timing[z = h[]; Do[z = h[z, {i, -i}], {i, 1*^6}]; Length@z] > Timing[Length[zz = List @@ Flatten[z, Infinity, h]]] > > Out[1]= {1.6739,2} > > Out[2]= {0.622828,1000000} > > In[3]:= Timing[s = {}; Do[s = {s, {i, -i}}, {i, 1*^6}]; Length@z] > Timing[Length[ss = Partition[Flatten[s], Length[Last@s]]]] > > Out[3]= {1.61893,2} > > Out[4]= {0.392044,1000000} > > In[5]:= ss == zz > > Out[5]= True The timing seems to be version-dependent. In[1]:= {$Version, $ReleaseNumber} Out[1]= {5.2 for Mac OS X (June 20, 2005), 0} In[2]:= Timing[z = h[]; Do[z = h[z, {i, -i}], {i, 1*^6}]; Length@z] Timing[Length[zz = List @@ Flatten[z, Infinity, h]]] Out[2]= {4.24 Second,2} Out[3]= {0.74 Second,1000000} In[4]:= Timing[s = {}; Do[s = {s, {i, -i}}, {i, 1*^6}]; Length@s] Timing[Length[ss = Partition[Flatten[s], Length[Last@s]]]] Out[4]= {3.96 Second,2} Out[5]= {1.2 Second,1000000} In[6]:= ss == zz Out[6]= True In[1]:= {$Version, $ReleaseNumber} Out[1]= {6.0 for Mac OS X PowerPC (32-bit) (June 19, 2007), 1} In[2]:= Timing[z = h[]; Do[z = h[z, {i, -i}], {i, 1*^6}]; Length@z] Timing[Length[zz = List @@ Flatten[z, Infinity, h]]] Out[2]= {5.36, 2} Out[3]= {0.76, 1000000} In[4]:= Timing[s = {}; Do[s = {s, {i, -i}}, {i, 1*^6}]; Length@s] Timing[Length[ss = Partition[Flatten[s], Length[Last@s]]]] Out[4]= {5.24, 2} Out[5]= {1.17, 1000000} In[6]:= ss == zz Out[6]= True