on master help sign in
normalize zip benches, add mergeAsyncByM benchmark
26354baHarendra Kumar
benchmark/LinearAsync.hs+9−5
@@ -28,9 +28,9 @@ benchIO value name f = bench name $ nfIO $ randomRIO (1,1) >>= f . Ops.source va
28-- | Takes a source, and uses it with a default drain/fold method.
28-- | Takes a source, and uses it with a default drain/fold method.
29{-# INLINE benchSrcIO #-}
29{-# INLINE benchSrcIO #-}
30benchSrcIO
30benchSrcIO
31− :: (t IO Int -> SerialT IO Int)
31+ :: (t IO a -> SerialT IO a)
32 -> String
32 -> String
33− -> (Int -> t IO Int)
33+ -> (Int -> t IO a)
34 -> Benchmark
34 -> Benchmark
35benchSrcIO t name f
35benchSrcIO t name f
36 = bench name $ nfIO $ randomRIO (1,1) >>= Ops.toNull t . f
36 = bench name $ nfIO $ randomRIO (1,1) >>= Ops.toNull t . f
@@ -130,10 +130,14 @@ main = do
130 (Ops.concatStreamsWith ahead (value2 * 2) (value2 `div` 2))
130 (Ops.concatStreamsWith ahead (value2 * 2) (value2 `div` 2))
131 ]
131 ]
132 , bgroup "zip"
132 , bgroup "zip"
133− [ benchIO value "zip" Ops.zipAsync
133+ [ benchSrcIO serially "zipAsync (2,x/2)" (Ops.zipAsync (value `div` 2))
134+ , benchSrcIO serially "zipAsyncM (2,x/2)"
134− , benchIO value "zipM" Ops.zipAsyncM
135+ (Ops.zipAsyncM (value `div` 2))
136+ , benchSrcIO serially "zipAsyncAp (2,x/2)"
135− , benchIO value "zipAp" Ops.zipAsyncAp
137+ (Ops.zipAsyncAp (value `div` 2))
136 , benchIO value "fmap zipAsyncly" $ Ops.fmap' zipAsyncly 1
138 , benchIO value "fmap zipAsyncly" $ Ops.fmap' zipAsyncly 1
139+ , benchSrcIO serially "mergeAsyncByM (2,x/2)"
140+ (Ops.mergeAsyncByM (value `div` 2))
137 -- Parallel stages in a pipeline
141 -- Parallel stages in a pipeline
138 , benchIO value "parAppMap" Ops.parAppMap
142 , benchIO value "parAppMap" Ops.parAppMap
139 , benchIO value "parAppSum" Ops.parAppSum
143 , benchIO value "parAppSum" Ops.parAppSum
benchmark/Streamly/Benchmark/Prelude.hs+24−18
@@ -29,7 +29,6 @@ import Control.Monad.IO.Class (MonadIO(..))
29import Control.Monad.State.Strict (StateT, get, put)
29import Control.Monad.State.Strict (StateT, get, put)
30import Data.Functor.Identity (Identity, runIdentity)
30import Data.Functor.Identity (Identity, runIdentity)
31import Data.IORef (newIORef, modifyIORef')
31import Data.IORef (newIORef, modifyIORef')
32−import Data.Maybe (fromJust)
33import GHC.Generics (Generic)
32import GHC.Generics (Generic)
34import Prelude
33import Prelude
35 (Monad, Int, (+), ($), (.), return, fmap, even, (>), (<=), (==), (>=),
34 (Monad, Int, (+), ($), (.), return, fmap, even, (>), (<=), (==), (>=),
@@ -718,25 +717,32 @@ inspect $ 'zipM `hasNoType` ''D.Step
718#endif
717#endif
719
718
720{-# INLINE zipAsync #-}
719{-# INLINE zipAsync #-}
720+zipAsync :: (S.IsStream t, S.MonadAsync m) => Int -> Int -> t m (Int, Int)
721+zipAsync count n = do
722+ S.zipAsyncWith (,)
723+ (sourceUnfoldrMN count n)
724+ (sourceUnfoldrMN count (n + 1))
725+
721{-# INLINE zipAsyncM #-}
726{-# INLINE zipAsyncM #-}
727+zipAsyncM :: (S.IsStream t, S.MonadAsync m) => Int -> Int -> t m (Int, Int)
728+zipAsyncM count n = do
729+ S.zipAsyncWithM (curry return)
730+ (sourceUnfoldrMN count n)
731+ (sourceUnfoldrMN count (n + 1))
732+
722{-# INLINE zipAsyncAp #-}
733{-# INLINE zipAsyncAp #-}
723−zipAsync, zipAsyncAp, zipAsyncM :: S.MonadAsync m => Stream m Int -> m ()
734+zipAsyncAp :: (S.IsStream t, S.MonadAsync m) => Int -> Int -> t m (Int, Int)
724−
725−zipAsync src = do
726− r <- S.tail src
727− let src1 = fromJust r
728− transform (S.zipAsyncWith (,) src src1)
729−
730−zipAsyncM src = do
731− r <- S.tail src
732− let src1 = fromJust r
733− transform (S.zipAsyncWithM (curry return) src src1)
734−
735−zipAsyncAp src = do
735+zipAsyncAp count n = do
736− r <- S.tail src
737− let src1 = fromJust r
738− transform (S.zipAsyncly $ (,) <$> S.serially src
736+ S.zipAsyncly $ (,)
739− <*> S.serially src1)
737+ <$> (sourceUnfoldrMN count n)
738+ <*> (sourceUnfoldrMN count (n + 1))
739+
740+{-# INLINE mergeAsyncByM #-}
741+mergeAsyncByM :: (S.IsStream t, S.MonadAsync m) => Int -> Int -> t m Int
742+mergeAsyncByM count n = do
743+ S.mergeAsyncByM (\a b -> return (a `compare` b))
744+ (sourceUnfoldrMN count n)
745+ (sourceUnfoldrMN count (n + 1))
740
746
741-------------------------------------------------------------------------------
747-------------------------------------------------------------------------------
742-- Multi-stream folds
748-- Multi-stream folds