       Timing of a simple table operation

• To: mathgroup at yoda.physics.unc.edu
• Subject: Timing of a simple table operation
• From: Jeffrey K. MacKie-Mason <jmm at umich.edu>
• Date: Fri, 7 Aug 92 13:19:40 EDT

```I created a list of numbers with Table, then calculated the product
of 1 plus each element in the list.  I want to calculate many such
products, so I nested this inside another Table, but found that it
took *forever* to calculate.  I can illustrate this but having the
outer Table create only one product of an inner Table, and then do
the same thing without the outer Table.  The Table-nested approach
tool 5 minutes (NeXT '040-25mHz), the piecemeal approach took about
0.3 seconds!

I'm pretty new to Mma, and I understand recursion is a tricky beast,
but since I can create this massive delay when the outer Table is
only one element long I'm baffled.  Suggestions?

home/jmm.12> math
Mathematica 2.0 for NeXT
-- NeXT graphics initialized --

In:= <<Statistics`ContinuousDistributions`

In:= rdist = NormalDistribution[(1.1^(1/240)-1),(0.2/240)]

Out= NormalDistribution[0.000397205, 0.000833333]

In:= annualReturns=Timing[Table[
(Product[
(1+Table[Random[rdist],{240}][[i]]),
{i,1,240}
] - 1),
{1}
]]

Out= {312.933 Second, {0.109928}}

In:= y = Timing[Table[Random[rdist],{240}]][]

Out= {-0.000684265,  < list of 240 numbers suppressed> }

In:= Timing[Product[(1+y[[i]]),{i,1,240}]-1]

Out= {0.266667 Second, 0.114892}

So, the nested Tables took 5 minutes, the direct (two-step) approach
less than 0.3 seconds.

What dumb thing am I doing?

---
Prof. Jeff MacKie-Mason	    	  internet:    jmm at umich.edu
Dept. of Economics                bitnet:   usergc76 at umichum
Univ. of Michigan                 phone:        313-764-7438
Ann Arbor, MI 48109-1220          fax:          313-763-9181

```

• Prev by Date: [no subject]
• Next by Date: [no subject]
• Previous by thread: [no subject]
• Next by thread: [no subject]