Created
November 2, 2015 22:06
-
-
Save michaelt/1281265722e88b0a7425 to your computer and use it in GitHub Desktop.
https://github.com/jwiegley/streaming-tests modified for use with `streaming` `io-streams` `machines` etc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import qualified Streaming.Prelude as Str | |
import qualified System.IO.Streams as IOS | |
import qualified ListT as ListT | |
import Data.Conduit as C | |
import Data.Conduit.Combinators as C | |
import qualified Data.Machine as M | |
import qualified Data.Machine.Runner as M | |
import Pipes as P | |
import qualified Pipes.Prelude as P | |
import Conduit.Simple as S | |
import Control.Exception | |
import Criterion.Main | |
import Data.Function ((&)) | |
import Control.Monad | |
main :: IO () | |
main = do | |
defaultMain [ | |
bgroup "basic" [bench "stream" $ nfIO stream_basic | |
, bench "conduit" $ nfIO conduit_basic | |
, bench "simple-conduit" $ nfIO simple_conduit_basic | |
, bench "pipes" $ nfIO pipes_basic | |
, bench "data-list" $ nfIO list_basic | |
, bench "iostreams" $ nfIO iostreams_basic | |
, bench "machines" $ nfIO machine_basic | |
] | |
] | |
machine_basic = do | |
xs <- M.runT $ M.enumerateFromTo 1 limit | |
M.~> M.filtered even | |
M.~> M.auto (+1) | |
M.~> M.dropping 1000 | |
M.~> M.auto (+1) | |
M.~> M.filtered (\x -> x `mod` 2 == 0) | |
assert (Prelude.length xs == len) $ | |
return (Prelude.length xs) | |
limit = 1000000 :: Int | |
len = 499000 :: Int | |
pipes_basic :: IO Int | |
pipes_basic = do | |
xs <- P.toListM $ P.each [1..limit] | |
>-> P.filter even | |
>-> P.map (+1) | |
>-> P.drop 1000 | |
>-> P.map (+1) | |
>-> P.filter (\x -> x `mod` 2 == 0) | |
assert (Prelude.length xs == len) $ | |
return (Prelude.length xs) | |
conduit_basic :: IO Int | |
conduit_basic = do | |
xs <- C.yieldMany [1..limit] | |
C.$= C.filter even | |
C.$= C.map ((+1) :: Int -> Int) | |
C.$= (C.drop 1000 >> C.awaitForever C.yield) | |
C.$= C.map ((+1) :: Int -> Int) | |
C.$= C.filter (\x -> x `mod` 2 == 0) | |
C.$$ C.sinkList | |
assert (Prelude.length xs == len) $ | |
return (Prelude.length (xs :: [Int])) | |
simple_conduit_basic :: IO Int | |
simple_conduit_basic = do | |
xs <- S.sourceList [1..limit] | |
S.$= S.filterC even | |
S.$= S.mapC ((+1) :: Int -> Int) | |
S.$= S.dropC 1000 | |
S.$= S.mapC ((+1) :: Int -> Int) | |
S.$= S.filterC (\x -> x `mod` 2 == 0) | |
S.$$ S.sinkList | |
assert (Prelude.length xs == len) $ | |
return (Prelude.length (xs :: [Int])) | |
list_basic :: IO Int | |
list_basic = do | |
xs <- Prelude.mapM return [1..limit] | |
>>= \ns -> return $ | |
ns & Prelude.filter even | |
& Prelude.map (+1) | |
& Prelude.drop 1000 | |
& Prelude.map (+1) | |
& Prelude.filter (\x -> x `mod` 2 == 0) | |
assert (Prelude.length xs == len) $ | |
return (Prelude.length (xs :: [Int])) | |
stream_basic :: IO Int | |
stream_basic = do | |
xs <- Str.toList_ | |
. Str.filter (\x -> x `mod` 2 == 0) | |
. Str.map (+1) | |
. Str.drop 1000 | |
. Str.map (+1) | |
. Str.filter even | |
$ Str.each [1..limit] | |
assert (Prelude.length xs == len) $ | |
return (Prelude.length (xs :: [Int])) | |
iostreams_basic :: IO Int | |
iostreams_basic = do | |
s0 <- IOS.fromList [1..limit] | |
s1 <- IOS.filter even s0 | |
s2 <- IOS.map (+1) s1 | |
s3 <- IOS.drop 1000 s2 | |
s4 <- IOS.map (+1) s3 | |
s5 <- IOS.filter (\x -> x `mod` 2 == 0) s4 | |
xs <- IOS.toList s5 | |
assert (Prelude.length xs == len) $ | |
return (Prelude.length (xs :: [Int])) | |
Author
michaelt
commented
Nov 2, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment