
Khudyakov Alexey schrieb:
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.
If you use top-level definition 'xs' the program might cache the list and second write is faster. You may change the order of tests in order check, whether that is the cause.