Size of Compiled Program

Marc Schütz via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jan 4 06:16:54 PST 2016


On Monday, 4 January 2016 at 13:49:03 UTC, Martin Tschierschke 
wrote:
> When I was writing a small speed test - D versus Ruby,
> calculating the first n prime numbers, I realized, that for 
> small n
> Ruby may be faster, than compiling and executing with D.
> But for n = 1,000,000 D outperforms Ruby by app. 10x.
>
> Looking at the size of my prime executable, it was around 800 
> kB with DMD
> and even with optimization and "gdc -Os" > 1 MB.
> Why is such a short program resulting in a so big binary?

That's probably basic these compilers statically link the runtime 
(and standard?) libraries by default. Compiling your program with 
`ldc2 -O3`, I get a binary of 28K, and stripping gets it down to 
17K.


More information about the Digitalmars-d-learn mailing list