[Haskell-cafe] Efficient string output
Johan Tibell
johan.tibell at gmail.com
Mon Feb 9 06:55:36 EST 2009
On Mon, Feb 9, 2009 at 12:49 PM, Ketil Malde <ketil at malde.org> wrote:
> 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.
Is building the strict ByteString what takes the most time? If so, you
might want to use `writev` to avoid extra copying. Does your data
support incremental processing so that you could produce output before
all input has been parsed?
Cheers,
Johan
More information about the Haskell-Cafe
mailing list