on master help sign in
Add bind style benchmark for simple-conduit
992195eHarendra Kumar
benchmark/Main.hs+18
@@ -85,6 +85,7 @@ main = do
85 , bench "logict" $ nfIO logict_basic
85 , bench "logict" $ nfIO logict_basic
86 , bench "list-t" $ nfIO list_t_basic
86 , bench "list-t" $ nfIO list_t_basic
87 , bench "simple-conduit" $ nfIO simple_conduit_basic
87 , bench "simple-conduit" $ nfIO simple_conduit_basic
88+ , bench "simple-conduit-bind" $ nfIO simple_conduit_bind
88 , bench "machines" $ nfIO machines_basic
89 , bench "machines" $ nfIO machines_basic
89 ]
90 ]
90#endif
91#endif
@@ -270,6 +271,23 @@ simple_conduit_basic = do
270 assert (Prelude.length xs == 49900) $
271 assert (Prelude.length xs == 49900) $
271 return (Prelude.length (xs :: [Int]))
272 return (Prelude.length (xs :: [Int]))
272
273
274+smap :: Monad (s IO) => (Int -> Int) -> Int -> s IO Int
275+smap = Main.map
276+
277+sfilter :: (Alternative (s IO), Monad (s IO)) => (Int -> Bool) -> Int -> s IO Int
278+sfilter = Main.filter
279+
280+{-# INLINE simple_conduit_bind #-}
281+simple_conduit_bind :: IO Int
282+simple_conduit_bind = do
283+ xs <- S.sinkList $ do
284+ S.dropC 100 (S.sourceList [1..100000 :: Int] >>= \x ->
285+ sfilter even x >>= smap (+1))
286+ >>= smap (+1)
287+ >>= sfilter (\y -> y `mod` 2 == 0)
288+ assert (Prelude.length xs == 49900) $
289+ return (Prelude.length xs)
290+
273machines_basic :: IO Int
291machines_basic :: IO Int
274machines_basic = do
292machines_basic = do
275 xs <- M.runT $ M.source [1..100000]
293 xs <- M.runT $ M.source [1..100000]