## digitalmars.D.learn - is D so slow?

- baleog (28/28) Jun 14 2008 Hello
- janderson (6/36) Jun 14 2008 To me your code looks reasonable, although you probably want to take the...
- Charles Hixson (6/13) Jun 14 2008 wouldn't that be:
- janderson (5/20) Jun 14 2008 Actually it should be:

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; }

Jun 14 2008

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; }To me your code looks reasonable, although you probably want to take the startup time and the gc out of the equation since that cost is fixed. BTW: here's a slightly more optimal reverse loop: for(int i = n; --i>0; ) -Joel

Jun 14 2008

On Sat, 14 Jun 2008 11:34:20 -0700, janderson wrote:...To me your code looks reasonable, although you probably want to takethestartup time and the gc out of the equation since that cost is fixed. BTW: here's a slightly more optimal reverse loop: for(int i = n; --i>0; ) -Joelwouldn't that be: for(int i = n; i-- >0; ) ? first time through i == n-1, last time through i == 0.

Jun 14 2008

Charles Hixson wrote:On Sat, 14 Jun 2008 11:34:20 -0700, janderson wrote:Actually it should be: for(int i = n; --i>=0; ) (missed the >=) -Joel...To me your code looks reasonable, although you probably want to takethestartup time and the gc out of the equation since that cost is fixed. BTW: here's a slightly more optimal reverse loop: for(int i = n; --i>0; ) -Joelwouldn't that be: for(int i = n; i-- >0; ) ? first time through i == n-1, last time through i == 0.

Jun 14 2008