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

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

Search the Archive

Re: compile / optimize

  • To: mathgroup at smc.vnet.net
  • Subject: [mg53716] Re: compile / optimize
  • From: Paul Abbott <paul at physics.uwa.edu.au>
  • Date: Mon, 24 Jan 2005 03:37:51 -0500 (EST)
  • Organization: The University of Western Australia
  • References: <comgvp$9hg$1@smc.vnet.net> <copavk$ps8$1@smc.vnet.net> <csl1pm$6ve$1@smc.vnet.net> <csnstt$4cr$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

In article <csnstt$4cr$1 at smc.vnet.net>,
 "Jens-Peer Kuska" <kuska at informatik.uni-leipzig.de> wrote:

> ff = Experimental`OptimizeExpression[
> Module[{x = 0}, Do[x += Sin[t^2]/(1 + x), {12}]; x]]
> 
> 
> myfun=Compile[{{t, _Real}}, Evaluate[ff]]

However, using OptimizeExpression with Compile does not give any speed 
up for the given problem. Compare the following timings:

  g = Nest[Function[t, (t + x/t)/2], x, 15];

  f1 = Compile[{{x, _Real}}, Evaluate[g]];

  First[Timing[vals1 = f1 /@ Range[0.1, 20., 0.001]; ]]
  0.11 Second

  f2 = Compile[{{x, _Real}},
    Evaluate[Experimental`OptimizeExpression[Evaluate[g]]]]; 

  First[Timing[vals2 = f2 /@ Range[0.1, 20., 0.001]; ]]   
  0.1 Second
  
  vals1 == vals2
  True

Cheers,
Paul

> "Frank Brand" <frank.brand at t-online.de> schrieb im Newsbeitrag 
> news:csl1pm$6ve$1 at smc.vnet.net...
> > Dear mathgroup members,
> >
> > can anybody give me an advice how to generally
> >
> > 1.optimize (using the optimization package "optimize.m") and after that
> > 2. compile pieces of code like
> >
> > Module[{t}, t = x; Do[t = (t + x/t)/2, {n}]; t]

Note that this code is much clearer as

  Nest[Function[t, (t + x/t)/2], x, n]

And, of course, NewtonIteration is built-in (FindRoot).

> > Applying the two-step approach to the code above with a given n (=15)
> > there is a speed up ratio of 8500 compared with the original exprssion.
> >
> > Is it possible to apply this procedure to general expressions?
> >
> > Thanks in advance
> > Frank

-- 
Paul Abbott                                   Phone: +61 8 6488 2734
School of Physics, M013                         Fax: +61 8 6488 1014
The University of Western Australia      (CRICOS Provider No 00126G)         
35 Stirling Highway
Crawley WA 6009                      mailto:paul at physics.uwa.edu.au 
AUSTRALIA                            http://physics.uwa.edu.au/~paul


  • Prev by Date: Re: Preventing Times[x,x] from becoming Power[x,2]
  • Next by Date: Re: Numbers and their reversals
  • Previous by thread: Re: compile / optimize
  • Next by thread: compile / optimize