Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #1795

Re: Another AppendTo replacement problem

From Ray Koopman <koopman@sfu.ca>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Another AppendTo replacement problem
Date 2011-04-20 08:28 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <iom5g5$c$1@smc.vnet.net> (permalink)
References <ioek97$mvg$1@smc.vnet.net>

Show all headers | View raw


On Apr 18, 6:50 am, Bill Rowe <readn...@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

Back to comp.soft-sys.math.mathematica | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Re: Another AppendTo replacement problem Bill Rowe <readnews@sbcglobal.net> - 2011-04-17 11:52 +0000
  Re: Another AppendTo replacement problem Ray Koopman <koopman@sfu.ca> - 2011-04-20 08:28 +0000

csiph-web