Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #1770
| From | Ray Koopman <koopman@sfu.ca> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Another AppendTo replacement problem |
| Date | 2011-04-17 23:15 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <iofsav$s3r$1@smc.vnet.net> (permalink) |
| References | <iobv13$bfp$1@smc.vnet.net> <ioek85$muk$1@smc.vnet.net> |
On Apr 17, 4:51 am, "Sjoerd C. de Vries" <sjoerd.c.devr...@gmail.com>
wrote:
> The usual trick is to replace AppendTo[list,elem] with list {list,elem}.
See Maxim Rytin, "Two heads are better than one",
http://forums.wolfram.com/mathgroup/archive/2006/May/msg00175.html
The trick he suggests builds just as fast as,
and unravels twice as fast as, the usual trick.
Timing[s = {}; Do[s = {s, h[i,-i] }, {i,1*^6}]; Length@s]
Timing[Length[ss = Flatten@s /. h->List]]
{4.23 Second,2}
{1.82 Second,1000000}
Timing[z = h[]; Do[z = h[z, {i,-i} ], {i,1*^6}]; Length@z]
Timing[Length[zz = List @@ Flatten[z,Infinity,h]]]
{4.25 Second,2}
{0.71 Second,1000000}
zz === ss
True
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: Another AppendTo replacement problem Iván Lazaro <gaminster@gmail.com> - 2011-04-16 11:37 +0000
Re: Another AppendTo replacement problem ADL <alberto.dilullo@tiscali.it> - 2011-04-17 11:51 +0000
Re: Another AppendTo replacement problem "Sjoerd C. de Vries" <sjoerd.c.devries@gmail.com> - 2011-04-17 11:51 +0000
Re: Another AppendTo replacement problem Ray Koopman <koopman@sfu.ca> - 2011-04-17 23:15 +0000
csiph-web