is D so slow?

baleog maccarka at yahoo.com
Sun Jun 15 04:53:30 PDT 2008


Thank you for your replies! I used malloc instead of new and run time was about 1sec

p.s. i'm sorry for my terrible english

Tomas Lindquist Olsen Wrote:

> baleog wrote:
> > Hello
> > I wrote 2 almost identical test programs(matrix multiplication). One on C and another on D. And D prorgram was 15 times slower! 
> > Was it my mistake or not?
> > Thank you
> > 
> > p.s. code:
> > void test (int n) {  
> >   float[] xs = new float[n*n];
> >   float[] ys = new float[n*n];
> >   for(int i = n-1; i>=0; --i) {
> >     xs[i] = 1.0;
> >   }
> >  for(int i = n-1; i>=0; --i) {
> >     ys[i] = 2.0;
> >   }
> >   float[] zs = new float[n*n];
> >   for (int i=0; i<n; ++i) {
> >     for (int j=0; j<n; ++j) {
> >       float s = 0.0;
> >       for (int k=0; k<n; ++k) {
> >         s = s + (xs[k + (i*n)] * ys[j + (k*n)]);
> >       }
> >       zs[j+ (i*n)] =  s;
> >     }
> >   }
> >   delete xs;
> >   delete ys;
> >   delete zs;
> > }
> > 
> 
> What switches did you use to compile? Not much info you're giving ...
> 
> Tomas



More information about the Digitalmars-d-learn mailing list