
Great, thanks. Those suggestions narrow the gap from GHC -O being 330x slower than GCC -O3 to it being 20x slower. Here are the new results: gcc -O3 0.54s ocamlopt 1.11s ghc -O 10.76s ocamlc 14.10s GHC is still pretty slow for native x86 instruction code. Is there any way to further explain the performance gap ? (new code below) Thanks! Lex Haskell (GHC) source: import Array k :: Array Int Int k = Array.array (0,15) [(i, i+1) | i <- [0 .. 15] ] acc :: Int -> Int acc 0 = 0 acc n = seq (k Array.! (n `mod` 16)) (acc (n-1)) main = do print (acc 100000000) Caml test source: let a = Array.make 16 0;; let rec do1 i z = if (i>100000000) then z else do1 (i+1) (z + a.(i mod 16));; do1 0 0;; C (gcc) test source: int main () { int i, k = 0; int a [16]; for (i=0; i<100000000; i++) { k += a [i % 16]; } return (k); } On Fri, 27 Jun 2003, Sven Panne wrote:
Well, part of the answer is definitely that the Haskell program is the *only* one which really uses the array elements. :-) I guess that the compilers for the other languages simply remove the array access from the generated code (gcc definitely does, only an empty loop remains).
Another reason is that the type signatures are missing, so Integer is used instead of Int, which is a bit unfair. Adding
k :: Array Int Int acc :: Int -> Int
cuts down the time by more than factor 5 on my machine.
Cheers, S.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe