On Thu, 02 Jun 2011 10:36:54 -0400, bearophile <[email protected]>
wrote:
In some (not benchmark) D2 code I have this (variable names changed):
int[2][8] array;
...
array[i] = [x, y];
Such lines of code are not inside the inner loop, that's in the "..."
part. Despite they are not in the inner loop I've seen that replacing
this line:
array[i] = [x, y];
with:
array[i][0] = x;
array[i][1] = y;
reduces the run time from about 1.8 seconds to about 1.05 seconds :-)
If I change the matrix type like this:
int[][8] array;
The runtime goes to about 1.55 seconds, because using dynamic arrays
just for two integers is not so efficient for other parts of the code.
(I have also tried to replace the int[2] with a Tuple!(int,int) but this
seems to give small problems elsewhere in my code, I have not tried this
hard enough yet.)
I'd like DMD to compile and perform this very simple line of code in a
much more efficient way:
array[i] = [x, y];
Bye,
bearophile
bearophile, array literals default to dynamic arrays, which require an
allocation, etc. IIRC, originally, literals specified fixed sized arrays,
but was considered unexpected behavior and reduced usability and was
changed.