On 4 March 2013 14:50, J <private@private-dont-email-dont-spam.com> wrote:
On Monday, 4 March 2013 at 04:22:01 UTC, bearophile wrote:
So this should be better:

http://codepad.org/B5b4uyBM

Bye,
bearophile

@bearophile: Thank you!  Unfortunately the http://codepad.org/B5b4uyBM code runs a bit *slower* than the original D code. Yikes!

$  gdmd -O -inline -release -noboundscheck -m64 bear.d -ofdbear
$ time ./dbear
-1015380632 859379360 -367726792 -1548829944

real    2m36.971s
user    2m36.910s
sys 0m0.030s
$ time ./dbear
-1015380632 859379360 -367726792 -1548829944

real    2m34.425s
user    2m34.370s
sys 0m0.020s


@John Colvin: here is the disassembly of mmult() in both languages. Unfortunately I'm not literate in x86_64 assembly.  Perhaps the problem is obvious to you?  All I can really tell is that the g++ version is shorter.

The memory allocation, when timed separately (comment out mmult), is less than 60 msec for either version, so I don't think its a memory issue, although it could be caching issue since the matrix layouts are different.

Using dynamic arrays of dynamic arrays that way is pretty poor form regardless of the language.

You should really use single dimensional array:
  int matrix[SIZE*SIZE];
And index via: 
  matrix[y*SIZE+x]

(You can pretty this up in various ways, if this is too unsightly)


On 4 March 2013 14:02, John Colvin <john.loughran.colvin@gmail.com> wrote:
    int[][] m = new int[][](rows, cols);

Does D support proper square array's this way? Or does it just automate allocation of the inner arrays?
Does it allocate all the associated memory in one block?