@@ -7,6 +7,7 @@ import Control.Applicative (Alternative(..))
7import Control.Exception (assert)
7import Control.Exception (assert)
8import Control.Monad (guard)
8import Control.Monad (guard)
9import Criterion.Main (defaultMain, bgroup, bench, nfIO)
9import Criterion.Main (defaultMain, bgroup, bench, nfIO)
10+import Data.Function ((&))
11import qualified Asyncly as A
12import qualified Asyncly as A
12import qualified Asyncly.Prelude as A
13import qualified Asyncly.Prelude as A
@@ -37,7 +38,9 @@ main = do
37 ap = asyncly_parallel
38 ap = asyncly_parallel
38 defaultMain [
39 defaultMain [
39 bgroup "asyncly"
40 bgroup "asyncly"
41+ [ bench "function style all serial" $ nfIO asyncly_function_style
40− [ bgroup "serial bind"
43+ , bgroup "serial bind"
41 [ bench "serial" $ nfIO (as (A.<>))
44 [ bench "serial" $ nfIO (as (A.<>))
42 , bench "fair serial" $ nfIO (as (A.<=>))
45 , bench "fair serial" $ nfIO (as (A.<=>))
43 , bench "left parallel" $ nfIO (as (A.<|))
46 , bench "left parallel" $ nfIO (as (A.<|))
@@ -103,18 +106,31 @@ afilter = Main.filter
104{-# INLINE asyncly_basic #-}
107{-# INLINE asyncly_basic #-}
105asyncly_basic
108asyncly_basic
106− :: (Alternative (s IO), Monad (s IO), Monoid (s IO Int), A.Streaming s) => (forall a. s IO a -> IO [a])
109+ :: (Alternative (t IO), Monad (t IO), A.Streaming t)
110+ => (forall a. t IO a -> IO [a])
107− -> (s IO Int -> s IO Int -> s IO Int)
111+ -> (t IO Int -> t IO Int -> t IO Int)
108 -> IO Int
112 -> IO Int
109asyncly_basic tl g = do
113asyncly_basic tl g = do
110 xs <- tl $ do
114 xs <- tl $ do
111 A.drop 100 (A.forEachWith g [1..100000 :: Int] $ \x ->
115 A.drop 100 (A.forEachWith g [1..100000 :: Int] $ \x ->
112− afilter even x `f` amap (+1))
116+ afilter even x >>= amap (+1))
113− `f` amap (+1)
117+ >>= amap (+1)
118+ >>= afilter (\y -> y `mod` 2 == 0)
119+ assert (Prelude.length xs == 49900) $
120+ return (Prelude.length xs)
122+{-# INLINE asyncly_function_style #-}
123+asyncly_function_style :: IO Int
124+asyncly_function_style = do
125+ xs <- A.toList $ A.serially $
126+ A.each [1..100000 :: Int]
114− `f` afilter (\y -> y `mod` 2 == 0)
131+ & A.filter (\y -> y `mod` 2 == 0)
115 assert (Prelude.length xs == 49900) $
132 assert (Prelude.length xs == 49900) $
116 return (Prelude.length xs)
133 return (Prelude.length xs)
119{-# INLINE asyncly_serial #-}
135{-# INLINE asyncly_serial #-}
120asyncly_serial
136asyncly_serial