[Haskell-cafe] Re: speed: ghc vs gcc

ChrisK haskell at list.mightyreason.com
Fri Feb 20 10:11:46 EST 2009


On a G4:

s.hs (which does not need bang patterns) is:

> main = seq (sum0 (10^9) 0) (return ())
> 
> sum0 :: Int -> Int -> Int
> sum0 0 acc = acc
> sum0 x acc = sum0 (x-1) $! (acc+x)

And s.c is (actually including 10^9, which Bulat's did not):

> main()
> {
>   int sum=0;
>   for(int i=1000*1000*1000; i>0; i--)
>       sum += i;
> }

I compiled them with

ghc --make -O2 s.hs -o shs
gcc -o sc -std=c99 -O3 -funroll-loops s.c

And timed them:

$ time ./shs

real	0m3.309s
user	0m3.008s
sys	0m0.026s

$ time ./sc

real	0m0.411s
user	0m0.316s
sys	0m0.006s

So C is 9.4 times faster.

And via-C did not help:

$ ghc -fvia-C -optc "-O3 -funroll-loops" --make -O2 s.hs -o shs-via-C
$ time ./shs-via-C

real	0m7.051s
user	0m3.010s
sys	0m0.050s

-- 
Chris



More information about the Haskell-Cafe mailing list