Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

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

Search the Archive

Re: Unusual speedup of Table

  • To: mathgroup at smc.vnet.net
  • Subject: [mg25610] Re: Unusual speedup of Table
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Mon, 16 Oct 2000 03:04:36 -0400 (EDT)
  • Organization: Universitaet Leipzig
  • References: <8s1798$ii7@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

try

Developer`SetSystemOptions["TableCompileLength" -> 20000]

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


and you will get the speed of your  Table[Switch[]] version.

I would expect that the compilation of the Part[] calls are
translated into compiled reference to an external

{{1, 3}, {26, Function[{j}, a], 2, 0, 0, 3, 0, 0}, 
 {9, 1, 1}, {29, 0, 1, 1}, {26, Function[{j}, a], 2, 0, 0, 
  3, 0, 1}, {9, 1, 2}, {29, 0, 2, 2}, 
 {27, Part, 3, 0, 1, 2, 0, 2, 3, 0, 2}, {9, 2, 3}, 
 {26, Function[{j}, a], 2, 0, 0, 3, 0, 3}, 
 {26, Function[{j}, a[[j]]], 2, 0, 0, 3, 0, 5}, 
 {19, 1, 3, 6}, {34, 6, 5, 3}, {38, 3, 4}, 
 {26, Function[{j}, a], 2, 0, 0, 3, 0, 5}, {9, -1, 3}, 
 {29, 0, 3, 3}, {26, Function[{j}, a], 2, 0, 0, 3, 0, 6}, 
 {9, -1, 4}, {29, 0, 4, 4}, {27, Part, 3, 0, 6, 2, 0, 4, 3, 
  0, 7}, {30, 2, 4, 7, 0}, {4, 0}}

and the Function[{j}, a[[j]]] will destroy the usual speed up 
for compilation. While

{{1, 3}, {26, Function[{j}, Which[j == _, 
    a[[j + 1]] - 2*a[[j]] + a[[j - 1]]]], 2, 0, 0, 3, 0, 0}, 
 {4, 0}}

make a much lower number of function calls.

Regards
  Jens

SATether wrote:
> 
> 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: Re: tracing lines on surface-graphics
  • Next by Date: Graphics Directives Lost In Certain Cases
  • Previous by thread: Re: Unusual speedup of Table
  • Next by thread: ReplaceAll in Element[] Q