[Haskell-cafe] OCaml list sees abysmal Language Shootout results]
haskell at sleepingsquirrel.org
Thu Sep 30 11:06:14 EDT 2004
Sam Mason wrote:
> You probably want some strictness annotations in there. . .
Now we're getting somewhere. When I replace the tuples with my own
(strict) data structure, it gets about 7.5 times faster than the original
shootout example (or about 24 times faster than the version with
tuples). I get another 2x speedup when I pass '+RTS -G1' to the
executable. So the version below is about 15 times faster than the
original using the 3MB data file from the shootout. (Now we're only
about 40x slower than ocaml). Don't forget to turn on '-funbox-strict-fields'
for an additional improvement.
-- Compile with...
-- ghc -O2 -ddump-simpl -fvia-c -funbox-strict-fields -o wc_fold2 wc_fold2.hs
-- execute as... ./wc_fold2 +RTS -G1 <input.txt
main = do file <- getContents
putStrLn $ show (foldl wc (St 0 0 0) file)
data Stuple = St !Int !Int !Int deriving Show
wc (St l w c) '\n' = St (l+1) w (c+1)
wc (St l w c) ' ' = St l (w+1) (c+1)
wc (St l w c) x = St l w (c+1)
...It still seems like it's using a lot of memory (or at least doing a
lot of garbage collecting). But it it still vastly better than before.
Is there any way to reduce this more? (60,000,000 bytes divided by
3,000,000 chars = 20 bytes per char). Here's the memory usage report...
61,387,752 bytes allocated in the heap
11,837,148 bytes copied during GC
99,780 bytes maximum residency (234 sample(s))
234 collections in generation 0 ( 0.11s)
1 Mb total memory in use
INIT time 0.00s ( 0.00s elapsed)
MUT time 0.15s ( 0.15s elapsed)
GC time 0.11s ( 0.14s elapsed)
EXIT time 0.00s ( 0.00s elapsed)
Total time 0.26s ( 0.29s elapsed)
%GC time 42.3% (48.3% elapsed)
Alloc rate 409,251,680 bytes per MUT second
Productivity 57.7% of total user, 51.7% of total elapsed
More information about the Haskell-Cafe