Jump to page: 1 2
Thread overview
Code optimization
Oct 24, 2005
Tiago Gasiba
Oct 24, 2005
zwang
Oct 24, 2005
Tiago Gasiba
Oct 24, 2005
Hasan Aljudy
Oct 24, 2005
Tiago Gasiba
Oct 24, 2005
Sean Kelly
Oct 24, 2005
Tiago Gasiba
Oct 24, 2005
Dave
Oct 24, 2005
Tiago Gasiba
Oct 24, 2005
Dave
Oct 24, 2005
Walter Bright
Oct 25, 2005
Daniel Horn
Oct 26, 2005
Walter Bright
Oct 26, 2005
Sean Kelly
Oct 24, 2005
James Dunne
Oct 24, 2005
Walter Bright
Oct 28, 2005
Thomas Kuehne
October 24, 2005
Hi *,

  How good is the DMD compiler code optimization?
  As a researcher, I write programs mainly to do simulations.
  Normally the software does not have any GUI and should run "damm fast".
  It is not unusual that some simulations take as much as 2 or 3 weeks to finish.
  Therefore, if a compiler can save only 10% of running time, this is very much wellcome - independent of how big the output file is (i.e. optimize for speed, not for space).
  Recently, while playing with DMD, I wrote a program to simulate LDPC codes (encoding/decoding).
  To try out the code, I ran a very simple simulation which took me about 2min to finish.
  Then, I have compiled the same program with "dmd -O" and, surprise! No reduction in exectution time at all!
  How good is the D code generation optimization? How does it compare to GCC? How should a program be written in order to make it fast?
  Let me refrase it - what should we avoid while writting a D program in order to make it run fast?
  I have two good things to mention:
    1) the code written in D is much more straight-forward and much more understandable than the C version
    2) the execution time was only slightly higher than the one obtained for the GCC version of the program.
  Now the bad news:
    1) this comparison is not fair, since I have used smarter programming for D than for C... maybe I'll try the same "trick" in C and it will be even faster...

  How mature is D code optimization compared to GCC? What should we expect in the (near) future? Remember that GCC is already in version 4.x, while D is 0.x!
  Last but not the least, how do I profile my code to make it faster?

Thanks,
Tiago

-- 
Tiago Gasiba (MSc.) - http://www.gasiba.de
Everything should be made as simple as possible, but not simpler.
October 24, 2005
Tiago Gasiba wrote:
<snip>
>   Last but not the least, how do I profile my code to make it faster?


dmd -profile
October 24, 2005
zwang schrieb:

> Tiago Gasiba wrote:
> <snip>
>>   Last but not the least, how do I profile my code to make it faster?
> 
> 
> dmd -profile

Shame on me! :(
That's nice... I've made my code at least 3x faster :)
Now... is there a nice GUI for the "trace.log" or do I have to write it myself? ;)
Dumm question, I know...

Thanks,
Tiago

-- 
Tiago Gasiba (M.Sc.) - http://www.gasiba.de
Everything should be made as simple as possible, but not simpler.
October 24, 2005
Tiago Gasiba wrote:

>   Then, I have compiled the same program with "dmd -O" and, surprise! No reduction in exectution time at all!

hmm .. try "dmd -release -O"
don't know if that'll make a difference! but it's just something to try.
October 24, 2005
Hasan Aljudy schrieb:

> Tiago Gasiba wrote:
> 
>>   Then, I have compiled the same program with "dmd -O" and, surprise! No
>>   reduction in exectution time at all!
> 
> hmm .. try "dmd -release -O"
> don't know if that'll make a difference! but it's just something to try.

Simulation time results:

compilation method: dmd -O -release
real    1m15.055s
user    1m11.948s
sys     0m0.136s

compilation method: dmd -O
real    1m26.488s
user    1m24.425s
sys     0m0.076s

compilation method: dmd
real    1m25.107s
user    1m23.949s
sys     0m0.060s

Apparently, the -release flag does "something", i.e. it lowered the execution time by 10sec.
It might have just been "luck" and the CPU was less busy when I ran the first simulation.
Nevertheless, compiling the code with or without optimization had no impact on the performance! :(

Best,
Tiago

-- 
Tiago Gasiba (MSc.) - http://www.gasiba.de
Everything should be made as simple as possible, but not simpler.
October 24, 2005
In article <djio77$s95$1@digitaldaemon.com>, Tiago Gasiba says...
>
>Apparently, the -release flag does "something", i.e. it lowered the execution time by 10sec.
>It might have just been "luck" and the CPU was less busy when I ran the first simulation.
>Nevertheless, compiling the code with or without optimization had no impact on the performance! :(

-release removes any in/out contract checking in the code, asserts, and bounds checking for arrays.  Try -release with and without "-O -inline" added to see the effects of the DM optimizer.


Sean


October 24, 2005
In article <djio77$s95$1@digitaldaemon.com>, Tiago Gasiba says...
>
>Hasan Aljudy schrieb:
>
>> Tiago Gasiba wrote:
>> 
>>>   Then, I have compiled the same program with "dmd -O" and, surprise! No
>>>   reduction in exectution time at all!
>> 
>> hmm .. try "dmd -release -O"
>> don't know if that'll make a difference! but it's just something to try.
>
>Simulation time results:
>
>compilation method: dmd -O -release
>real    1m15.055s
>user    1m11.948s
>sys     0m0.136s
>
>compilation method: dmd -O
>real    1m26.488s
>user    1m24.425s
>sys     0m0.076s
>
>compilation method: dmd
>real    1m25.107s
>user    1m23.949s
>sys     0m0.060s
>
>Apparently, the -release flag does "something", i.e. it lowered the execution time by 10sec.
>It might have just been "luck" and the CPU was less busy when I ran the first simulation.
>Nevertheless, compiling the code with or without optimization had no impact on the performance! :(
>
>Best,
>Tiago
>

Now try 'dmd -O -release -inline' and see if that makes a difference. If you are making a lot of functions calls, the optimizations may not make much of a difference unless frequently called functions are also inlined because of the call overhead.

If your code is integer intensive, -O will generally make a difference for tight loops. If it is fp intensive -O will generally /not/ make a big difference right now.

In general, DMD does well vs. GCC and other compilers, but of course your milage may vary <g>:

http://shootout.alioth.debian.org/benchmark.php?test=all&lang=all&sort=fullcpu

The bottleneck right now is primarily in the allocator and GC if you plan to de/allocate a lot of objects in a tight loop. There are a number of ways to use D's flexibility to work around that though:

http://digitalmars.com/d/memory.html

>-- 
>Tiago Gasiba (MSc.) - http://www.gasiba.de
>Everything should be made as simple as possible, but not simpler.


October 24, 2005
Sean Kelly schrieb:

> In article <djio77$s95$1@digitaldaemon.com>, Tiago Gasiba says...
>>
>>Apparently, the -release flag does "something", i.e. it lowered the execution time by 10sec. It might have just been "luck" and the CPU was less busy when I ran the first simulation. Nevertheless, compiling the code with or without optimization had no impact on the performance! :(
> 
> -release removes any in/out contract checking in the code, asserts, and
> bounds
> checking for arrays.  Try -release with and without "-O -inline" added to
> see the effects of the DM optimizer.
> 
> 
> Sean

Results for  dmd -release -O -inline:
real    1m14.794s
user    1m12.113s
sys     0m0.224s

Results for  dmd -release:
real    1m18.049s
user    1m15.149s
sys     0m0.180s

Didnt make much difference... :(

Tiago

-- 
Tiago Gasiba (MSc.) - http://www.gasiba.de
Everything should be made as simple as possible, but not simpler.
October 24, 2005
Dave schrieb:

> 
> If your code is integer intensive, -O will generally make a difference for tight loops. If it is fp intensive -O will generally /not/ make a big difference right now.

Yeap! Its highly FP intensive. In fact, I'm spending all the time just doing FP operations.
I can say, however, that the results I obtain with D are very good, but I got somehow surprized why the -O was not producing any speedup.
BTW, I removed all the function calls "by hand" long time back :)
When you mean "right now" what does that mean? Is there a plan to work this out?

> 
> In general, DMD does well vs. GCC and other compilers, but of course your milage may vary <g>:
> 
> http://shootout.alioth.debian.org/benchmark.php?test=all&lang=all&sort=fullcpu

I have seen this some time back and was wandering how much effort was being put into the code optimization. I also know this is a though topic to deal with...

> The bottleneck right now is primarily in the allocator and GC if you plan to de/allocate a lot of objects in a tight loop. There are a number of ways to use D's flexibility to work around that though:
> 
> http://digitalmars.com/d/memory.html

I'll take a look at this... might be interesting to know some "black magic" here :)

Last but not the least, I would like to refer that the "user" can not expect the "compiler" to speedup dumm/sloppy/poorly written code.
I'm trying my best to write something fast but that does not mean that I'm not interested in knowing how much can the compiler help me.
I would like to congratulate you guys because DMD does (already) a very good job.

Thanks,
Tiago

-- 
Tiago Gasiba (MSc.) - http://www.gasiba.de
Everything should be made as simple as possible, but not simpler.
October 24, 2005
Tiago Gasiba wrote:
> Hi *,
> 
>   How good is the DMD compiler code optimization?
>   As a researcher, I write programs mainly to do simulations.
>   Normally the software does not have any GUI and should run "damm fast".
>   It is not unusual that some simulations take as much as 2 or 3 weeks to finish.
>   Therefore, if a compiler can save only 10% of running time, this is very much wellcome - independent of how big the output file is (i.e. optimize for speed, not for space).
>   Recently, while playing with DMD, I wrote a program to simulate LDPC codes (encoding/decoding).
>   To try out the code, I ran a very simple simulation which took me about 2min to finish.
>   Then, I have compiled the same program with "dmd -O" and, surprise! No reduction in exectution time at all!
>   How good is the D code generation optimization? How does it compare to GCC? How should a program be written in order to make it fast?
>   Let me refrase it - what should we avoid while writting a D program in order to make it run fast?
>   I have two good things to mention:
>     1) the code written in D is much more straight-forward and much more understandable than the C version
>     2) the execution time was only slightly higher than the one obtained for the GCC version of the program.
>   Now the bad news:
>     1) this comparison is not fair, since I have used smarter programming for D than for C... maybe I'll try the same "trick" in C and it will be even faster...
> 
>   How mature is D code optimization compared to GCC? What should we expect in the (near) future? Remember that GCC is already in version 4.x, while D is 0.x!
>   Last but not the least, how do I profile my code to make it faster?
> 
> Thanks,
> Tiago
> 

Tiago,

Since you seem to be basing your benchmarks on GCC (the backend specifically), why not try out GDC?  It's a D front end compiler attached to the GCC backend system.  I'm not sure of the state of the front end's optimizations in that port, but noting that it has the GCC backend might be of interest to you.  Check it out, it's on the "D Links" page.

You might have to do a bit of GCC compiling on your system to get a working GDC.  cygwin seems to already have a GDC package available for installation if you're running on Windows and don't feel like compiling GCC.

-- 
Regards,
James Dunne
« First   ‹ Prev
1 2