18 Mar 2013 09:53
Streaming bytes and performance
Konstantin Litvinenko <to.darkangel <at> gmail.com>
2013-03-18 08:53:13 GMT
2013-03-18 08:53:13 GMT
Hi All!
I tune my toy project for performance and hit the wall on simple, in
imperative world, task. Here is the code that model what I'm trying to
achieve
import qualified Data.ByteString.Lazy as L
import Data.Word8(isSpace)
import Data.Word
import Control.Monad.State
type Stream = State L.ByteString
get_byte :: Stream (Maybe Word8)
get_byte = do
s <- get
case L.uncons s of
Nothing -> return Nothing
Just (x, xs) -> put xs >> return (Just x)
main = do
f <- L.readFile "test.txt"
let r = evalState count_spaces f
print r
where
count_spaces = go 0
where
go a = do
x <- get_byte
case x of
(Continue reading)
RSS Feed