MathGroup Archive 2003

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

Search the Archive

Increase in efficiency with Module


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