MathGroup Archive 1999

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

Search the Archive

speed (resumed)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg15724] speed (resumed)
  • From: tobias at physics.odu.edu
  • Date: Fri, 5 Feb 1999 03:42:21 -0500 (EST)
  • Organization: Deja News - The Leader in Internet Discussion
  • Sender: owner-wri-mathgroup at wolfram.com

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

Out[1]=
{56.8977 Second, 6.47467520 10*^1497}

In[2]:= Timing[x=0.3;Print[x];Nest[Function[{y},y 1.003456],x,1000000]]
0.3

Out[2]=
{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
linear...

I'd like to know if anyone knew other tricks that reduce computation
time just by changing the notation ?

Tobias

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own



  • Prev by Date: Re: Mathematica and OPENSTEP
  • Next by Date: Speed (resumed)
  • Previous by thread: Re: Options for Cell: Why are some of these System symbols and others not?
  • Next by thread: Speed (resumed)