Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: Cost of Composition vs Pure Function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg93665] Re: Cost of Composition vs Pure Function
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Fri, 21 Nov 2008 05:32:23 -0500 (EST)

On 11/20/08 at 4:56 AM, raffy at mac.com (Raffy) wrote:

>The speed difference between these two evaluations seems odd,
>considering they are effectively the same thing:

>m = RandomReal[{0, 1}, {10, 1000, 1000}];

>Total[Total[#]]& /@ m; // Timing => 0.14 sec

>Composition[Total, Total] /@ m; // Timing => 0.983 sec

>Other than the Identity and Inverse Function transformation, where
>is this overhead coming from?

I don't why there is an overhead associated with Compositon.
But, there clearly is an overhead used when mapping a function
to elements. Note

In[1]:= m = RandomReal[{0, 1}, {10, 1000, 1000}];

In[2]:= (x = Total[Total[#]] & /@ m); // Timing

Out[2]= {0.836466,Null}

In[3]:= (y = Total[m, {2, 3}]); // Timing

Out[3]= {0.207775,Null}

In[4]:= x == y

Out[4]= True

That is you can get the same result more efficiently by using
the second argument to Total and avoid the overhead associated
with Map.


  • Prev by Date: Re: Cost of Composition vs Pure Function
  • Next by Date: Re: ListPlot w/ Dynamic[] choice of external data files
  • Previous by thread: Re: Cost of Composition vs Pure Function
  • Next by thread: Re: Cost of Composition vs Pure Function