Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #2560 > unrolled thread

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

Started byGuillermo Sanchez <guillermo.sanchez@hotmail.com>
First post2011-05-21 10:47 +0000
Last post2011-05-22 10:53 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  The same function the second time evaluated is faster. Why? Guillermo Sanchez <guillermo.sanchez@hotmail.com> - 2011-05-21 10:47 +0000
    Re: The same function the second time evaluated is faster. Why? Joseph Gwinn <joegwinn@comcast.net> - 2011-05-22 10:53 +0000

#2560 — The same function the second time evaluated is faster. Why?

FromGuillermo Sanchez <guillermo.sanchez@hotmail.com>
Date2011-05-21 10:47 +0000
SubjectThe same function the second time evaluated is faster. Why?
Message-ID<ir857q$beh$1@smc.vnet.net>
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

[toc] | [next] | [standalone]


#2586

FromJoseph Gwinn <joegwinn@comcast.net>
Date2011-05-22 10:53 +0000
Message-ID<irapvg$lku$1@smc.vnet.net>
In reply to#2560
In article <ir857q$beh$1@smc.vnet.net>,
 Guillermo Sanchez <guillermo.sanchez@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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web