[Haskell-cafe] Efficient string output

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Mon Feb 9 07:38:21 EST 2009


On Mon, 2009-02-09 at 12:49 +0100, Ketil Malde wrote:
> 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:

Have you considered using Data.Binary to output the data too? It has a
pretty efficient underlying monoid for accumulating output data in a
buffer. You'd want some wrapper functions over the top to make it a bit
nicer for your use case, but it should work and should be quick.

It generates a lazy bytestring, but does so with a few large chunks so
the IO will still be quick.

Duncan



More information about the Haskell-Cafe mailing list