[Haskell-cafe] memory issues

Daniel Fischer daniel.is.fischer at web.de
Fri Feb 27 19:10:44 EST 2009


Am Samstag, 28. Februar 2009 00:37 schrieb Bulat Ziganshin:
> Hello Daniel,
>
> Saturday, February 28, 2009, 2:21:31 AM, you wrote:
> >>   printf "%s" $ unlines $ map (show) (sort $! blocks content)
> >
> > Bad!
> > Use
> >         mapM_ print $ sort $ blocks content
>
> are you sure?

Tested it. The printf "%s" is very bad. Replacing that reduced allocation and 
GC time by a factor of 2+.
The difference between 

mapM_ print

and

putStr $ unlines $ map show $ ...

is too small for me to be sure that mapM_ print is really better.

> print may waste a lot of time, locking stdout for every
> line printed

Hm, maybe

main = do
    args <- getArgs
    content <- B.readFile (args!!0)
    hout <- openFile (args!!1) WriteMode
    mapM_ (hPrint hout) $ sort $ blocks content
    hClose hout

? I find hardly any difference, though.



More information about the Haskell-Cafe mailing list