Thread overview | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
June 02, 2008 Why DMD is so slow? | ||||
---|---|---|---|---|
| ||||
Attachments: | I have written the code reported below to test execution speed of D in Windows and I have found that the same code is about 10 times slower if compiled using DMD w.r.t. GCD: 1.9 minutes in DMD vs 1.84 seconds in GDC ! Is there perhaps something wrong? why such a difference? Thank you. // begin of file mandel_d1.d /* DMD: dmd -inline -release -O mandel_d1.d GCD: gdc -O3 --fast-math -inline -lgphobos --expensive-optimizations mandel_d1.d */ import std.stdio; int main() { cdouble a, b, c, z; double mand_re = 0, mand_im = 0; for (double y = -2; y < 2; y += 0.01) { for (double x = -2; x < 2; x += 0.01) { z = (x + mand_re) + (y + mand_im) * 1i; c = z; for (int i = 0; i < 10000; i++) { z = z * z + c; if(z.re * z.re + z.im * z.im > 4.0) { break; } } } } return 0; } // end of file mandel_d1.d ------------------ H:\Codici\Benchmarks> ..\timethis.exe mandel_d1 TimeThis : Command Line : mandel_d1 TimeThis : Start Time : Mon Jun 02 11:28:41 2008 TimeThis : Command Line : mandel_d1 TimeThis : Start Time : Mon Jun 02 11:28:41 2008 TimeThis : End Time : Mon Jun 02 11:30:35 2008 TimeThis : Elapsed Time : 00:01:54.234 H:\Codici\Benchmarks> ..\timethis mandel_gdc1 TimeThis : Command Line : mandel_gdc1 TimeThis : Start Time : Mon Jun 02 11:42:27 2008 TimeThis : Command Line : mandel_gdc1 TimeThis : Start Time : Mon Jun 02 11:42:27 2008 TimeThis : End Time : Mon Jun 02 11:42:29 2008 TimeThis : Elapsed Time : 00:00:01.843 |
June 02, 2008 Re: Why DMD is so slow? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marco | I am sorry: 1 minute vs 1 second is 60 times! (I was reasoning in terms of order of magnitude, but in this case the multiple is 60). |
June 02, 2008 Re: Why DMD is so slow? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marco | Marco wrote: > I have written the code reported below to test execution speed of D in Windows and I have found that the same code is about 10 times slower if compiled using DMD w.r.t. GCD: 1.9 minutes in DMD vs 1.84 seconds in GDC ! Is there perhaps something wrong? why such a difference? [snip] > cdouble a, b, c, z; > double mand_re = 0, mand_im = 0; [snip] IIRC DMD's backend is just not as good at optimizing floating-point code as GDC's backend (GCC) is. |
June 03, 2008 Re: Why DMD is so slow? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marco | This outputs ~2660ms on my pentium 4. Try profiling your code, or comparing the asm. ------------------ auto timer = new PerformanceCounter; timer.start(); cdouble a, b, c, z; double mand_re = 0, mand_im = 0; for (double y = -2; y < 2; y += 0.01) { for (double x = -2; x < 2; x += 0.01) { z = (x + mand_re) + (y + mand_im) * 1i; c = z; for (int i = 0; i < 10000; i++) { z = z * z + c; if(z.re * z.re + z.im * z.im > 4.0) { break; } } } } timer.stop(); int elapsedMsec = timer.milliseconds; writefln("Time elapsed: %s msec", elapsedMsec); |
June 03, 2008 Re: Why DMD is so slow? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marco | Marco wrote:
> I have written the code reported below to test execution speed of D in Windows and I have found that the same code is about 10 times slower if compiled using DMD w.r.t. GCD: 1.9 minutes in DMD vs 1.84 seconds in GDC ! Is there perhaps something wrong? why such a difference?
> Thank you.
>
> // begin of file mandel_d1.d
> /*
> DMD: dmd -inline -release -O mandel_d1.d
> GCD: gdc -O3 --fast-math -inline -lgphobos --expensive-optimizations mandel_d1.d
> */
>
> import std.stdio;
>
> int main()
> {
> cdouble a, b, c, z;
> double mand_re = 0, mand_im = 0;
>
> for (double y = -2; y < 2; y += 0.01) {
> for (double x = -2; x < 2; x += 0.01) {
> z = (x + mand_re) + (y + mand_im) * 1i;
> c = z;
> for (int i = 0; i < 10000; i++) {
> z = z * z + c;
> if(z.re * z.re + z.im * z.im > 4.0) {
> break;
> }
> }
> }
> }
> return 0;
> }
> // end of file mandel_d1.d
> ------------------
>
> H:\Codici\Benchmarks> ..\timethis.exe mandel_d1
>
> TimeThis : Command Line : mandel_d1
> TimeThis : Start Time : Mon Jun 02 11:28:41 2008
>
>
> TimeThis : Command Line : mandel_d1
> TimeThis : Start Time : Mon Jun 02 11:28:41 2008
> TimeThis : End Time : Mon Jun 02 11:30:35 2008
> TimeThis : Elapsed Time : 00:01:54.234
>
> H:\Codici\Benchmarks> ..\timethis mandel_gdc1
>
> TimeThis : Command Line : mandel_gdc1
> TimeThis : Start Time : Mon Jun 02 11:42:27 2008
>
>
> TimeThis : Command Line : mandel_gdc1
> TimeThis : Start Time : Mon Jun 02 11:42:27 2008
> TimeThis : End Time : Mon Jun 02 11:42:29 2008
> TimeThis : Elapsed Time : 00:00:01.843
>
It would be interesting to compare the ASM produced. DMD is not that great at floating point, doesn't unroll so well and has a longer startup time then GDC in my experience.
-Joel
|
June 03, 2008 Re: Why DMD is so slow? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marco | As everyone has said, these are problems in DMD and DMC.
DMD is not a bad compiler, but it doesn't have all of the optimizations that some other compilers are. For example, Microsoft's cl and Intel's icc might possibly beat gcc at this too (although they don't currently compile D code.)
Anyway, it's a matter of priorities. Improving the performance of DMD compiled programs is great, but making the D language work is more important. If GDC can do a good optimization job, that's great for it imho.
-[Unknown]
Marco wrote:
> I have written the code reported below to test execution speed of D in Windows and I have found that the same code is about 10 times slower if compiled using DMD w.r.t. GCD: 1.9 minutes in DMD vs 1.84 seconds in GDC ! Is there perhaps something wrong? why such a difference?
> Thank you.
>
> // begin of file mandel_d1.d
> /*
> DMD: dmd -inline -release -O mandel_d1.d
> GCD: gdc -O3 --fast-math -inline -lgphobos --expensive-optimizations mandel_d1.d
> */
>
> import std.stdio;
>
> int main()
> {
> cdouble a, b, c, z;
> double mand_re = 0, mand_im = 0;
>
> for (double y = -2; y < 2; y += 0.01) {
> for (double x = -2; x < 2; x += 0.01) {
> z = (x + mand_re) + (y + mand_im) * 1i;
> c = z;
> for (int i = 0; i < 10000; i++) {
> z = z * z + c;
> if(z.re * z.re + z.im * z.im > 4.0) {
> break;
> }
> }
> }
> }
> return 0;
> }
> // end of file mandel_d1.d
> ------------------
>
> H:\Codici\Benchmarks> ..\timethis.exe mandel_d1
>
> TimeThis : Command Line : mandel_d1
> TimeThis : Start Time : Mon Jun 02 11:28:41 2008
>
>
> TimeThis : Command Line : mandel_d1
> TimeThis : Start Time : Mon Jun 02 11:28:41 2008
> TimeThis : End Time : Mon Jun 02 11:30:35 2008
> TimeThis : Elapsed Time : 00:01:54.234
>
> H:\Codici\Benchmarks> ..\timethis mandel_gdc1
>
> TimeThis : Command Line : mandel_gdc1
> TimeThis : Start Time : Mon Jun 02 11:42:27 2008
>
>
> TimeThis : Command Line : mandel_gdc1
> TimeThis : Start Time : Mon Jun 02 11:42:27 2008
> TimeThis : End Time : Mon Jun 02 11:42:29 2008
> TimeThis : Elapsed Time : 00:00:01.843
>
|
June 03, 2008 Re: Why DMD is so slow? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Unknown W. Brackets | Unknown W. Brackets wrote:
> As everyone has said, these are problems in DMD and DMC.
>
> DMD is not a bad compiler, but it doesn't have all of the optimizations that some other compilers are. For example, Microsoft's cl and Intel's icc might possibly beat gcc at this too (although they don't currently compile D code.)
>
> Anyway, it's a matter of priorities. Improving the performance of DMD compiled programs is great, but making the D language work is more important. If GDC can do a good optimization job, that's great for it imho.
Which is why I think the LLVM project is so important. Many languages -> one optimizer -> many targets
|
June 03, 2008 Re: Why DMD is so slow? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert Fraser | On Tue, 03 Jun 2008 16:23:07 +0400, Robert Fraser <fraserofthenight@gmail.com> wrote:
> Unknown W. Brackets wrote:
>> As everyone has said, these are problems in DMD and DMC.
>> DMD is not a bad compiler, but it doesn't have all of the optimizations that some other compilers are. For example, Microsoft's cl and Intel's icc might possibly beat gcc at this too (although they don't currently compile D code.)
>> Anyway, it's a matter of priorities. Improving the performance of DMD compiled programs is great, but making the D language work is more important. If GDC can do a good optimization job, that's great for it imho.
>
> Which is why I think the LLVM project is so important. Many languages -> one optimizer -> many targets
The same goes for GCC as well.
|
June 03, 2008 Re: Why DMD is so slow? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert Fraser | Robert Fraser wrote:
> Unknown W. Brackets wrote:
>> As everyone has said, these are problems in DMD and DMC.
>>
>> DMD is not a bad compiler, but it doesn't have all of the optimizations that some other compilers are. For example, Microsoft's cl and Intel's icc might possibly beat gcc at this too (although they don't currently compile D code.)
>>
>> Anyway, it's a matter of priorities. Improving the performance of DMD compiled programs is great, but making the D language work is more important. If GDC can do a good optimization job, that's great for it imho.
>
> Which is why I think the LLVM project is so important. Many languages -> one optimizer -> many targets
GCC already offers that. On the other hand, I've read papers where people modified GCC for research purposes. One month spent on algorithms, one month on implementation, four months just learning how GCC works and where to insert the code. I would guess that LLVM is currently well factored and much more extensible.
|
June 03, 2008 Re: Why DMD is so slow? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Unknown W. Brackets | Did anybody verify DMC being faster?
I don't have DMC, but my DMD code ran in 2.6s iso more than a minute.
> As everyone has said, these are problems in DMD and DMC.
>
>
|
Copyright © 1999-2021 by the D Language Foundation