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

Alexander V Vershilov alexander.vershilov at gmail.com
Fri Feb 10 16:17:33 CET 2012


Fri, Feb 10, 2012 at 06:36:19AM -0600, Antoine Latter wrote
> 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:
> 
> http://hackage.haskell.org/packages/archive/blaze-builder/0.3.1.0/doc/html/Blaze-ByteString-Builder.html
> 
> Antoine
> 

Also if for storing matrix in binary form some serialization packages can be 
used:

Binary:  http://hackage.haskell.org/package/binary-0.5.1.0
Cereal: http://hackage.haskell.org/package/cereal-0.3.5.1
        http://hackage.haskell.org/package/cereal-ieee754


--
Alexander V Vershilov
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: Digital signature
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120210/4f181d54/attachment.pgp>


More information about the Beginners mailing list