[Haskell-beginners] Effective file I/O with bytestrings

Antoine Latter aslatter at gmail.com
Fri Feb 10 13:36:19 CET 2012

On Fri, Feb 10, 2012 at 3:31 AM, Johannes Engels
<johannes.engels at hft-stuttgart.de> wrote:
> Dear Haskellers,
> in several books (RWH, LYAH) I have found the statement that file I/O is
> more effective with bytestrings than with common strings. As I am doing
> mostly scientific programming and nearly every program of mine uses file
> I/O, I would like to check this. So I tried to write a small "benchmark":
> read a double matrix from file and write it to file again. Regarding to
> reading, the benefit of bytestrings was actually huge, it was about ten
> times faster than with strings. What refers to writing, however, I failed
> completely. Most important, I did not find a function which directly
> converts doubles to bytestrings. So the best I could figure out was the
> following ugly workaround using Text.Show.ByteString:

Using a ByteString as an accumulator can be not-great. A lot of folks
use some sort of specialized 'builder' type, like this one:



More information about the Beginners mailing list