Size of Compiled Program
Martin Tschierschke via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jan 4 05:49:03 PST 2016
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);
}
More information about the Digitalmars-d-learn
mailing list