[Haskell] ANNOUNCE: jhc 0.6.0 Haskell Compiler

sylvain sylvain.nahas at googlemail.com
Wed Mar 18 19:16:06 EDT 2009


This compiler is very promising, for the least.

Here is a small dummy Haskell program.
countdown :: Int -> IO ()
countdown 0 = putStrLn "finished"
countdown x = do 
		putStrLn (show x)
		countdown (x-1)
main = countdown 10000000

and the C program that comes to closest.
#include <stdio.h>
int main(void)
	int i;
	for(i=0; i<10000000; i++)
	return 0;

GHC is 6.10.1, gcc is 4.3.2, jhc is 0.6.0
arch is i386/Linux(Ubuntu)

$ ghc hello.hs -o hello1
$ jhc hello.hs -o hello2
$ gcc hello.c -o hello3

What about the size of the executables?
$ ls -l hello1 hello2 hello3
493567 hello1
16803 hello2
9083 hello3

let strip them.
309492 hello1
10092 hello2
5664 hello3

In the case of jhc, there is definitively room for some improvements.
I dare not say what I think of ghc.

Now, let run them.

$ time ./hello1 > /dev/null 
real	0m12.092s
user	0m12.005s
sys	0m0.052s

$ time ./hello2 > /dev/null 
real	0m2.016s
user	0m1.016s
sys	0m1.000s

$ time ./hello3 > /dev/null 
real	0m2.609s
user	0m2.588s
sys	0m0.020s

Actually, times varie between runs. It tends to decrease (except for the
ghc generated binary), so I suppose it is due to OS cache effects. 
Yet, I consistently observed that, according to "time", hello2 (jhc)
runs _faster_ than hello3 (gcc).

Something is wrong: how can Haskell be faster than C?

Last but not least, as well as generating fast code, jhc can make good
use of a C cross-compiler as back-end.

Well done.
Sylvain Nahas

More information about the Haskell mailing list