 
 
 
 
 
 
Re: The same function the second time evaluated is faster. Why?
- To: mathgroup at smc.vnet.net
- Subject: [mg119101] Re: The same function the second time evaluated is faster. Why?
- From: Joseph Gwinn <joegwinn at comcast.net>
- Date: Sun, 22 May 2011 06:52:24 -0400 (EDT)
- References: <ir857q$beh$1@smc.vnet.net>
In article <ir857q$beh$1 at smc.vnet.net>,
 Guillermo Sanchez <guillermo.sanchez at hotmail.com> wrote:
> Dear gurus?
> 
> 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?
> 
> Guillermo
Because Mathematica caches intermediate results.
Joe Gwinn

