MathGroup Archive 2008

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

Search the Archive

Re: Compiled function slowdown

  • To: mathgroup at smc.vnet.net
  • Subject: [mg86723] Re: [mg86682] Compiled function slowdown
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Wed, 19 Mar 2008 05:26:35 -0500 (EST)
  • References: <9949215.1205837642926.JavaMail.root@m08>
  • Reply-to: drmajorbob at longhorns.com

Send the e1, e2, and fComp functions, and I'll be curious to untangle this  
mess. Without them, it's incomprehensible.

Bobby

On Tue, 18 Mar 2008 04:50:04 -0500, mm1q <epv001 at lvc.edu> wrote:

> Hello,
>
> In a program I'm currently working on, I need to loop through a function  
> ~100,000 times.  I thought I'd try compiling it to save on time.   
> However, it takes more than 10 times longer to run than the uncompiled 
> (module) version.  Are there any general guidelines as to when a  
> compiled function will be slower than its uncompiled counterpart in  
> Mathematica (such as with the use of many conditional statements)?  I've  
> included my function below (sorry if it's a mess; e1, e2 and fComp are 
> very simple compiled functions), though a general response to the above  
> question would be just fine.  Thanks!
>
> generator = Compile[{stepTotAccum_Real, {dxTable, _Real, 1},
> pTile_Real, area_Real},
>       Do[
>         While[True,
>             u = Random[];
>             If[ u < stepTotAccum,
>               stats = 1 + 4*Floor[u/pTile];
>               cand = (u - dxTable[[stats + 2]])/dxTable[[stats + 1]]+
>             dxTable[[stats]];
>               If[Random[]*dxTable[[stats + 3]] < fComp[cand],
>                 Return[cand * (-1)^Random[Integer]]
>                 ];
>               ,
>               cand = e1[u];
>               If[e2[Random[], cand, area] < fComp[cand],
>                 Return[cand * (-1)^Random[Integer]]
>                 ];
>               ];
>             ];
>         ]
>       ];
>
>



-- 

DrMajorBob at longhorns.com


  • Prev by Date: Re: The size of a 3D plot
  • Next by Date: Re: importing nb files
  • Previous by thread: Re: Compiled function slowdown
  • Next by thread: Re: Compiled function slowdown