MathGroup Archive 2003

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

Search the Archive

Increase in efficiency with Module

  • To: mathgroup at smc.vnet.net
  • Subject: [mg40050] Increase in efficiency with Module
  • From: "Aaron E. Hirsh" <aehirsh at stanford.edu>
  • Date: Mon, 17 Mar 2003 03:35:18 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

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: Limiting the results
  • Next by Date: Re: Functions with multiple groups of arguments? [David Park?]
  • Previous by thread: Re: Limiting the results
  • Next by thread: Re: Increase in efficiency with Module