MathGroup Archive 2011

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

Search the Archive

Re: The same function the second time evaluated is faster. Why?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg119109] Re: The same function the second time evaluated is faster. Why?
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Sun, 22 May 2011 06:53:53 -0400 (EDT)

On 5/21/11 at 6:47 AM, guillermo.sanchez at hotmail.com (Guillermo
Sanchez) wrote:

>I evaluate the below function ,

>Int[1]:=1+1

>Int[2]:=Timing[(f2[x1_] := Integrate[Sin[x^3], {x, 0, x1}];
>f2[Range[10]]);]
>Out[2]:= {12.261, Null}

>I repeat the evaluation is faster

>Out[2]:={1.389, Null}

>and the third faster

>Out[3]:= {0.281, Null}

>Even writting f3 instead f2

>Timing[(f3[x1_] := Integrate[Sin[x^3], {x, 0, x1}]; f3[Range[10]]);]
>{0.281, Null}

>Why the second and third evaluation are faster?

Mathematica caches intermediate results. So, the second and
third evaluations use the cached results from previous
computations to save time.



  • Prev by Date: Re: how do I plot many points?
  • Next by Date: Re: Series[log[x], {x, 0, 3}]
  • Previous by thread: Re: The same function the second time evaluated is faster. Why?
  • Next by thread: Re: The same function the second time evaluated is faster. Why?