[Haskell-cafe] speed: ghc vs gcc
Dan Doel
dan.doel at gmail.com
Fri Feb 20 09:15:24 EST 2009
---- Test.hs ----
import Prelude hiding (sum, enumFromTo)
import Data.List.Stream (sum, unfoldr)
enumFromTo m n = unfoldr f m
where f k | k <= n = Just (k,k+1)
| otherwise = Nothing
main = print . sum $ enumFromTo 1 (10^9 :: Int)
---- snip ----
dolio at zeke % time ./Test
500000000500000000
./Test 3.12s user 0.03s system 80% cpu 3.922 total
dolio at zeke % time ./Test-sum0
500000000500000000
./Test-sum0 3.47s user 0.02s system 80% cpu 4.348 total
dolio at zeke % time ./Test-sum0
500000000500000000
./Test-sum0 3.60s user 0.02s system 90% cpu 4.009 total
dolio at zeke % time ./Test
500000000500000000
./Test 3.11s user 0.02s system 81% cpu 3.846 total
---- snip ----
"Test-sum0" is with the sum0 function
"Test" is the code at the top of this mail.
-fvia-c -optc-O3 didn't seem to make a big difference with either Haskell
example, so they're both with the default backend.
Your C++ code runs slowly on my system (around 1 second), but that's because
it uses 32-bit ints, I guess (switching to long int sped it up).
-- Dan
More information about the Haskell-Cafe
mailing list