Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1999

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

Search the Archive

Re: speed (resumed)

  • To: mathgroup at
  • Subject: [mg15789] Re: speed (resumed)
  • From: "Allan Hayes" <hay at>
  • Date: Sun, 7 Feb 1999 02:04:06 -0500 (EST)
  • References: <79e8qt$>
  • Sender: owner-wri-mathgroup at

Yes Function[x, expr[x]] has more to do than expr[#] & : in addition to
replacement via formal parameters it has also to check on scoping .

However, I wonder if the differences that you find between Map[f,g] and
f/@g are perhaps one-off since I get the following on a Toshiba Tecra
233 MgHz, 128 MgB RAM

  Timing[(#*2)& /@ Table[i,{i,10000}]][[1,1]]}, {20}


Take[data, 3]



Count[data, {x_,y_}/;#[x,y]]&/@{Less,Equal,Greater}



Allan Hayes
Mathematica Training and Consulting
hay at
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

tobias at wrote in message <79e8qt$9ea at>...
>Hi all, continuing on the speed of evaluation started in another thread
>about the difference between Do and Nest, I was wondering what you
>thought about the difference in evaluation time between pure functions
>written as
>(something depending on #i) & and
>Function[{vars},samething depending on vars]
>In[1]:= Timing[x=0.3;Print[x];Nest[# 1.003456 &,x,1000000]] 0.3
>{56.8977 Second, 6.47467520 10*^1497}
>In[2]:= Timing[x=0.3;Print[x];Nest[Function[{y},y 1.003456],x,1000000]]
>{79.2468 Second, 6.47467520 10*^1497}
>Using the Function notation increases the evaluation time by 40 %. I
>kind of understand this since in the Function case there has to be a
>replacement between the formal parameters and the arguments to be made
>which is not as streight forward as a replacement of #i by the
>arguments. On the other hand, I do not get at all the difference in
>evaluation time between
>Map[f,expr] and f /@ expr
>In[3]:= Timing[Map[(#*2)&,Table[i,{i,10000}]]][[1]]
>Out[3]= 1.63 Second
>In[4]:= Timing[(#*2)& /@ Table[i,{i,10000}]][[1]]
>Out[4]= 1.55 Second
>10 times more
>In[5]:= Timing[Map[(#*2)&,Table[i,{i,100000}]]][[1]]
>Out[5]= 16.31 Second
>In[6]:= Timing[(#*2)& /@ Table[i,{i,100000}]][[1]]
>Out[7]= 15.44 Second
>I expected that Map[] would be slower by a constant amount of time used
>for the translation to the other form but no it's more or less
>I'd like to know if anyone knew other tricks that reduce computation
>time just by changing the notation ?
>-----------== Posted via Deja News, The Discussion Network ==----------
>       Search, Read, Discuss, or Start Your Own

  • Prev by Date: NDSolve problem
  • Next by Date: Re: multiple linear regression
  • Previous by thread: Speed (resumed)
  • Next by thread: How to use DisplayTogether[] properly?