MathGroup Archive 2000

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

Search the Archive

Unusual speedup of Table

  • To: mathgroup at smc.vnet.net
  • Subject: [mg25605] Unusual speedup of Table
  • From: satether at aol.com (SATether)
  • Date: Wed, 11 Oct 2000 03:50:42 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Why is the second call of Table below so much faster than the first? These
results are from Mathematica 4.0.2.1 for Power Mac (400 MHz PPC 750, OS 9). It
isn't some kind of cache effect because the times are consistent over many
executions of both expressions. (And yes, I know I can do a lot better still
for this particular computation with Drop and Take).

- Steve Tether

n = 10000;
a = Table[Random[], {n}];
Timing[Table[a[[j + 1]] - 2 a[[j]] + a[[j - 1]], {j, 2, n - 1}];]

{10.5333 Second, Null}

Timing[Table[Switch[j, _, a[[j + 1]] - 2 a[[j]] + a[[j - 1]]], {j, 2, n - 1}];]

{0.7 Second, Null}


  • Prev by Date: integral of Bessel function, bug in Mathematica 4.0
  • Next by Date: ReplaceAll in Element[] Q
  • Previous by thread: Re: integral of Bessel function, bug in Mathematica 4.0
  • Next by thread: Re: Unusual speedup of Table