Loop optimization
    Walter Bright 
    newshound1 at digitalmars.com
       
    Fri May 21 18:42:10 PDT 2010
    
    
  
kai wrote:
> Here is a boiled down test case:
> 
> 	void main (string[] args)
> 	{
> 		double [] foo = new double [cast(int)1e6];
> 		for (int i=0;i<1e3;i++)
> 		{
> 			for (int j=0;j<1e6-1;j++)
> 			{
> 				foo[j]=foo[j]+foo[j+1];
> 			}
> 		}
> 	}
> 
> Any ideas?
for (int j=0;j<1e6-1;j++)
The j<1e6-1 is a floating point operation. It should be redone as an int one:
      j<1_000_000-1
    
    
More information about the Digitalmars-d-learn
mailing list