[Haskell-cafe] speed: ghc vs gcc

Bulat Ziganshin bulat.ziganshin at gmail.com
Fri Feb 20 08:29:29 EST 2009


Hello haskell-cafe,

since there are no objective tests comparing ghc to gcc, i made my own
one. these are 3 programs, calculating sum in c++ and haskell:

main = print $ sum[1..10^9::Int]


main = print $ sum0 (10^9) 0

sum0 :: Int -> Int -> Int
sum0 0  !acc = acc
sum0 !x !acc = sum0 (x-1) (acc+x)


main()
{
  int sum=0;
  //for(int j=0; j<100;j++)
    for(int i=0; i<1000*1000*1000;i++)
      sum += i;
  return sum;
}

execution times:
 sum:
   ghc 6.6.1 -O2               : 12.433 secs
   ghc 6.10.1 -O2              : 12.792 secs
 sum-fast:
   ghc 6.6.1 -O2               :  1.919 secs
   ghc 6.10.1 -O2              :  1.856 secs
   ghc 6.10.1 -O2 -fvia-C      :  1.966 secs
 C++:
   gcc 3.4.5 -O3 -funroll-loops:  0.062 secs


-- 
Best regards,
 Bulat                          mailto:Bulat.Ziganshin at gmail.com



More information about the Haskell-Cafe mailing list