7 Oct 05:17
Re: newbie questions (read, etc., with Data.ByteString.Lazy.Char8)
wman <666wman <at> gmail.com>
2008-10-07 03:17:45 GMT
2008-10-07 03:17:45 GMT
the problem is that using readInt is actually _as slow_, at least using my test script
(
(On Tue, Oct 7, 2008 at 5:12 AM, Don Stewart <dons <at> galois.com> wrote:
666wman:> a slight modification to compile it :Never unpack a bytestring.
>
> change:
> where sumFile = sum . map read . L.words
> to :
> where sumFile = sum . map (read . L.unpack) . L.words
>
> but it's actually _slower_ than the non-bytestring version.
import qualified Data.ByteString.Lazy.Char8 as S
main = print . go 0 =<< S.getContents
where
go n s = case S.readInt s of
Nothing -> n
Just (k,t) -> go (n+k) (S.tail t)
Assuming you're reading int, integers or doubles.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe <at> haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RSS Feed