MathGroup Archive 1999

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

Search the Archive

Speed (resumed)

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: speed (resumed)
  • Next by Date: Re: Programming the front end to save graphics files
  • Previous by thread: speed (resumed)
  • Next by thread: Re: speed (resumed)