[Haskell-cafe] Streaming bytes and performance

Don Stewart dons00 at gmail.com
Tue Mar 19 22:34:17 CET 2013


Oh I see what you're doing ... "Using this input file stored in /dev/shm"

So not measuring the IO performance at all. :)
On Mar 19, 2013 9:27 PM, "Peter Simons" <simons at cryp.to> wrote:

> Hi Don,
>
>  > Compare your program (made lazy) on lazy bytestrings using file IO:
> [...]
>
> if I make those changes, the program runs even faster than before:
>
>   module Main ( main ) where
>
>   import Prelude hiding ( foldl, readFile )
>   import Data.ByteString.Lazy.Char8
>
>   countSpace :: Int -> Char -> Int
>   countSpace i c | c == ' ' || c == '\n' = i + 1
>                  | otherwise             = i
>
>   main :: IO ()
>   main = readFile "test.txt" >>= print . foldl countSpace 0
>
> This gives
>
>  | $ ghc --make -O2 -funbox-strict-fields test1 && time ./test1
>  | 37627064
>  |
>  | real    0m0.375s
>  | user    0m0.346s
>  | sys     0m0.028s
>
> versus:
>
>  | $ ghc --make -O2 -funbox-strict-fields test2 && time ./test2
>  | 37627064
>  |
>  | real    0m0.324s
>  | user    0m0.299s
>  | sys     0m0.024s
>
> Whether getFile or getContents is used doesn't seem to make difference.
>
> Take care,
> Peter
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130319/e35ba63f/attachment.htm>


More information about the Haskell-Cafe mailing list