digitalmars.D.learn - Size of Compiled Program
- Martin Tschierschke (37/37) Jan 04 2016 When I was writing a small speed test - D versus Ruby,
- Basile B. (11/20) Jan 04 2016 You have the runtime and phobos compiled with your program. But
- Martin Tschierschke (3/12) Jan 04 2016 Ah, thank you for that Link!
- Marc =?UTF-8?B?U2Now7x0eg==?= (6/15) Jan 04 2016 That's probably basic these compilers statically link the runtime
- Martin Tschierschke (2/18) Jan 04 2016 Ok, I will try ldc2, too.
- Adam D. Ruppe (9/10) Jan 04 2016 The smallest possible ruby program has about ~5 MB of
- Martin Tschierschke (6/16) Jan 04 2016 Oh, thats interesting. When I tried to run the compiled "prime"
- Adam D. Ruppe (2/5) Jan 04 2016 Yeah, probably.
- Jacob Carlborg (5/9) Jan 05 2016 You can run the "file" command to see which architecture an executable
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? ----------------------------------------------------------------------------- import std.stdio; import std.conv; int[] prime; // Dynamic Array of Prime // Ist n durch eine der zahlen in prime teilbar? bool teilbar(int n){ for(auto i=0; prime[i]*prime[i]<=n ; i++){ if (n%prime[i]==0) return true; } return false; } void main(string[] args) // first parameter number of primes to calculate { auto anzahl = 10; // default prime ~= 2; // first element of the array if(args.length==2){ anzahl = to!int(args[1]);} auto pruefe=1; while (prime.length <= anzahl){ pruefe+=2; if(!teilbar(pruefe)){ write(" ",pruefe); prime ~= pruefe; // append the array } } write("\n das wars...:",prime.length); }
Jan 04 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?You have the runtime and phobos compiled with your program. But also: - if debug info are generated this increases the size. - if bounds checking is turned off there is some code generated for each array operation - if contracts are not off there is a lot of assertion that will be generated see also some clues here: http://forum.dlang.org/post/mailman.20.1441974998.22025.digitalmars-d-learn puremagic.com
Jan 04 2016
On Monday, 4 January 2016 at 14:01:18 UTC, Basile B. wrote:On Monday, 4 January 2016 at 13:49:03 UTC, Martin Tschierschke wrote:[...]- if debug info are generated this increases the size. - if bounds checking is turned off there is some code generated for each array operation - if contracts are not off there is a lot of assertion that will be generated see also some clues here: http://forum.dlang.org/post/mailman.20.1441974998.22025.digitalmars-d-learn puremagic.comAh, thank you for that Link!
Jan 04 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.
Jan 04 2016
On Monday, 4 January 2016 at 14:16:54 UTC, Marc Schütz wrote:On Monday, 4 January 2016 at 13:49:03 UTC, Martin Tschierschke wrote:Ok, I will try ldc2, too.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.
Jan 04 2016
On Monday, 4 January 2016 at 13:49:03 UTC, Martin Tschierschke wrote:When I was writing a small speed test - D versus RubyThe smallest possible ruby program has about ~5 MB of dependencies, outside the operating system (the ruby runtime itself). The D program has none. It carries its runtime with it, which makes the executable a bit larger to compensate but helps compatibility with other computers because the user doesn't have to hunt down obscure D runtime packages.
Jan 04 2016
On Monday, 4 January 2016 at 14:51:59 UTC, Adam D. Ruppe wrote:On Monday, 4 January 2016 at 13:49:03 UTC, Martin Tschierschke wrote:Oh, thats interesting. When I tried to run the compiled "prime" on my notebook, with the "same" Ubuntu release, I got an error, may be its 32 not 64 Bit? Any hint?When I was writing a small speed test - D versus RubyThe smallest possible ruby program has about ~5 MB of dependencies, outside the operating system (the ruby runtime itself). The D program has none. It carries its runtime with it, which makes the executable a bit larger to compensate but helps compatibility with other computers because the user doesn't have to hunt down obscure D runtime packages.
Jan 04 2016
On Monday, 4 January 2016 at 16:56:15 UTC, Martin Tschierschkewith the "same" Ubuntu release, I got an error, may be its 32 not 64 Bit? Any hint?Yeah, probably.
Jan 04 2016
On 2016-01-04 17:56, Martin Tschierschke wrote:Oh, thats interesting. When I tried to run the compiled "prime" on my notebook, with the "same" Ubuntu release, I got an error, may be its 32 not 64 Bit? Any hint?You can run the "file" command to see which architecture an executable is built for. -- /Jacob Carlborg
Jan 05 2016