Fwd: [Haskell-cafe] Data.Binary suboptimal instance

Khudyakov Alexey alexey.skladnoy at gmail.com
Sat May 23 12:58:42 EDT 2009


On Saturday 23 May 2009 02:55:17 Antoine Latter wrote:
> Or you could go for the compromise position, where the list can be
> part of a complex data structure so you're not relying on EOF to find
> the end.
>
Interesting solution however it does not perform very nice. I wrote 
microbenchmark

> xs :: [Word32]
> xs = [1..(10^6)]

Writing chunked list of Word32
> B.writeFile "chunked" . toLazyByteString . putList putWord32be $ xs
real    0m4.311s
user    0m3.272s
sys     0m0.096s

Reading chunked list of Word32
> print . last . runGet (getList getWord32be) =<< B.readFile "chunked"
real    0m0.634s
user    0m0.496s
sys     0m0.012s


Writing stream of Word32
> B.writeFile "stream" . encodeStream $ xs
real    0m0.391s
user    0m0.252s
sys     0m0.020s

Reading stream of Word32
> print . (last :: [Word32] -> Word32) . decodeStream =<< B.readFile "stream"
real    0m0.376s
user    0m0.248s
sys     0m0.020s


I didn'd do any profiling so I have no idea why writing is so slow.

-- 
  Best regard Khudyakov Alexey


More information about the Haskell-Cafe mailing list