<div dir="ltr"><div class="Ih2E3d">as usual, i forgot to use the magical "reply to all" and under the impression I'm still talking to the list had bothered dons personally (heresy/sacrilege/deathwish , i know)<br>
to rectify it a bit at least, i'm posting a summary, in hopes someone find it useful.<br>----------------------------<br>-- this doesn't work - space leak no matter which optimizations you use, with -O2 it crashes in 5 secs instead in 75 ;-)<br>
import qualified Data.ByteString.Lazy.Char8 as S<br>
main = print . go 0 =<< S.getContents<br> where<br> go n s = case S.readInt s of<br> Nothing -> n<br> Just (k,t) -> go (n+k) (S.tail t)<br><br>-- slightly stricter version, notice those ! before parameters in go declaration and the fancy -XBangPatterns option to ghc which it requires ;-)<br>
-- let dons_bstr.hs = <br><div class="Ih2E3d">import qualified Data.ByteString.Lazy.Char8 as S<br>main = print . go 0 =<< S.getContents<br>
where<br> go !n !s = case S.readInt s of<br> Nothing -> n<br> Just (k,t) -> go (n+k) (S.tail t)<br></div><br>ghc -XBangPatterns --make dons_bstr.hs <br> time dons_bstr < nums<br>
real 1m8.686s<br>user 0m0.015s<br>sys 0m0.031s<br><br>ghc -XBangPatterns -Onot -fstrictness --make dons_bstr.hs <br> time dons_bstr.exe < nums<br>real 1m10.607s<br>user 0m0.031s<br>sys 0m0.015s<br>
<br>
ghc -XBangPatterns -O2 --make dons_bstr.hs <br> time dons_bstr.exe < nums<br>real 0m1.500s<br>user 0m0.015s<br>sys 0m0.031s<br><br>so althought the -fstrictness still seems to have no effect in this case, using -O2 the dons version is ~2 times faster then the bytestring/readInt version -O2<br>
<br></div></div>