is D so slow?
Unknown W. Brackets
unknown at simplemachines.org
Sat Jun 14 17:35:58 PDT 2008
What about switches? Your program uses arrays; if you have array bounds
checks enabled, that could easily account for the difference.
One way to see is dump the assembly (I think there's a utility called
dumpobj included with dmd) and compare. Obviously, it's doing something
differently - there's nothing instrinsically "slower" about the language
for sure.
Also - keep in mind that gdc doesn't take advantage of all the
optimizations that gcc is able to provide, at least at this time. A
couple of bytes can go a long long way if not optimized right.
-[Unknown]
baleog wrote:
> Unknown W. Brackets Wrote:
>> What compilers are you comparing?
>
> gcc-4.0 with last releases of the gdc and dmd-2
>
>> They have different optimization
>
> but gdc uses gcc backend and the test programs (C and D) differs by the couple of bytes..
> i used std.gc.disable() too - nothing changed
>
>> backends. It could be that the C compiler or compiler flags you are
>> using simply perform better than the comparable D compiler and flags.
>>
>> -[Unknown]
>>
>>
>> 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;
>>> }
>>>
>
More information about the Digitalmars-d-learn
mailing list