large binaries
Jon Cast
jcast@ou.edu
Thu, 18 Jul 2002 14:09:30 -0500
Abraham Egnor <aegnor@antioch-college.edu> wrote:
> This is something I just noticed...
> hello.hs:
> module Main(main) where
> main = putStr "Hello world!\n"
> hello.c:
> #include <stdio.h>
> int main(void)
> {
> printf("Hello world!\n");
> return 0;
> }
> [abe@shiva:~/src/test] $ ghc hello.hs -o hello_hs
> [abe@shiva:~/src/test] $ gcc hello.c -o hello_c
> [abe@shiva:~/src/test] $ ls -l hello_*
> -rwxr-xr-x 1 abe engy 13712 Jul 18 11:34 hello_c
> -rwxr-xr-x 1 abe engy 299900 Jul 18 11:33 hello_hs
>
> Why is the binary made by ghc 20 times bigger than the one made by gcc?
I don't know for certain, but I've got a couple of guesses:
1. hello_hs is probably statically linked. hello_c is probably
dynamically linked.
2. "Hello world!\n" in Haskell is boxed; in C it's un-boxed. Ditto
for putStr vs. printf. The compiled code for the Haskell main appears
to have a lot of code to deal with those complications; multiply that
by however many functions are called by putStr.
> Abe
Jon Cast