
Fri, Feb 10, 2012 at 06:36:19AM -0600, Antoine Latter wrote
On Fri, Feb 10, 2012 at 3:31 AM, Johannes Engels
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/B...
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