Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1999
*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 1999

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

Search the Archive

Re: speed (resumed)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg15789] Re: speed (resumed)
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Sun, 7 Feb 1999 02:04:06 -0500 (EST)
  • References: <79e8qt$9ea@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Tobias,
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

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

Check

Take[data, 3]

    {{0.66,0.6},{0.66,0.55},{0.55,0.66}}

Compare

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

    {9,2,9}


Allan

---------------------
Allan Hayes
Mathematica Training and Consulting
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565


tobias at physics.odu.edu wrote in message <79e8qt$9ea at smc.vnet.net>...
>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: NDSolve problem
  • Next by Date: Re: multiple linear regression
  • Previous by thread: Speed (resumed)
  • Next by thread: How to use DisplayTogether[] properly?