[Haskell-cafe] Efficient string output

Don Stewart dons at galois.com
Mon Feb 9 12:44:49 EST 2009


ketil:
> 
> Hi,
> 
> I'm currently working on a program that parses a large binary file and
> produces various textual outputs extracted from it.  Simple enough.
> 
> But: since we're talking large amounts of data, I'd like to have
> reasonable performance.  
> 
> Reading the binary file is very efficient thanks to Data.Binary.
> However, output is a different matter.  Currently, my code looks
> something like:
> 
>       summarize :: Foo -> ByteString
>       summarize f = let f1 = accessor f
>                         f2 = expression f
>                            :
>                     in B.concat [f1,pack "\t",pack (show f2),...]
> 
> which isn't particularly elegant, and builds a temporary ByteString
> that usually only get passed to B.putStrLn.  I can suffer the
> inelegance were it only fast - but this ends up taking the better part
> of the execution time.

Why not use Data.Binary for output too? It is rather efficient at
output -- using a continuation-like system to fill buffers gradually.

--   Don


More information about the Haskell-Cafe mailing list