MathGroup Archive 2003

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

Search the Archive

Re: Increase in efficiency with Module

  • To: mathgroup at smc.vnet.net
  • Subject: [mg40074] Re: Increase in efficiency with Module
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Tue, 18 Mar 2003 05:50:59 -0500 (EST)
  • Organization: Universitaet Leipzig
  • References: <b5424l$mfr$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

with out the Module[] you are refering to i and j as external function
calls
and this slow down the compiled evaluation.

Regards
  Jens

"Aaron E. Hirsh" wrote:
> 
> I would be grateful if someone could explain the difference in
> efficiency between the following two simple programs. ry is a list of
> length n. For n = 1000, the program using Module takes 1 second on my
> laptop, whereas the program without Module takes 75 seconds.
> 
> ftauc = Compile[{{ry, _Real, 1}, {n, _Real, 0}},
> 
>     Module[{i,
> j, a},
> 
>       i = 1;
>       a = 0;
> 
>       Do[
> 
> 
> j = i + 1;
> 
>         Do[
>           If[ry[[i]] < ry[[j]], a++,
> If[ry[[i]] > ry[[j]], a--]];
>           j++, {n - i}];
> 
> 
> i++, {n - 1}]; a
>       ]]
> 
> ftauc2 = Compile[{{ry, _Real, 1}, {n, _Real, 0}},
> 
> 
> 
> 
> i = 1;
>     a = 0;
> 
>     Do[
> 
>       j = i + 1;
> 
> 
> Do[
>         If[ry[[i]] < ry[[j]], a++, If[ry[[i]] > ry[[j]], a--]];
> 
> j++, {n - i}];
> 
>       i++, {n - 1}]; a
> 
>     ]
> 
> thank you,
> --
> 
> Aaron E. Hirsh
> Center for Computational Genetics and Biological Modeling
> Department of Biological Sciences
> Stanford University
> tel. (650) 723-4952
> fax. (650) 725-0180


  • Prev by Date: Re: Odd memory behavior, and uncontrollable memory growth
  • Next by Date: Re: How to handle powers in c-code generation?
  • Previous by thread: Re: RE: Increase in efficiency with Module
  • Next by thread: RE: RE: Increase in efficiency with Module