on master help sign in
Add benchmarks for maxRate, maxThreads and maxBuffer
f09e741Harendra Kumar
benchmark/Linear.hs+14
@@ -126,6 +126,13 @@ main = do
126 , bgroup "asyncly"
126 , bgroup "asyncly"
127 [ -- benchIO "unfoldr" $ Ops.toNull asyncly
127 [ -- benchIO "unfoldr" $ Ops.toNull asyncly
128 benchSrcIO asyncly "unfoldrM" Ops.sourceUnfoldrM
128 benchSrcIO asyncly "unfoldrM" Ops.sourceUnfoldrM
129+ , benchSrcIO asyncly "unfoldrM maxThreads 1"
130+ (maxThreads 1 . Ops.sourceUnfoldrM)
131+ -- XXX arbitrarily large maxRate should be the same as maxRate -1
132+ , benchSrcIO asyncly "unfoldrM maxRate 1000000"
133+ (maxRate 1000000 . Ops.sourceUnfoldrM)
134+ , benchSrcIO asyncly "unfoldrM maxBuffer 1 (1000 ops)"
135+ (maxBuffer 1 . Ops.sourceUnfoldrMN 1000)
129 -- , benchSrcIO asyncly "fromFoldable" Ops.sourceFromFoldable
136 -- , benchSrcIO asyncly "fromFoldable" Ops.sourceFromFoldable
130 , benchSrcIO asyncly "fromFoldableM" Ops.sourceFromFoldableM
137 , benchSrcIO asyncly "fromFoldableM" Ops.sourceFromFoldableM
131 -- , benchSrcIO asyncly "foldMapWith" Ops.sourceFoldMapWith
138 -- , benchSrcIO asyncly "foldMapWith" Ops.sourceFoldMapWith
@@ -146,6 +153,13 @@ main = do
146 , bgroup "aheadly"
153 , bgroup "aheadly"
147 [ -- benchIO "unfoldr" $ Ops.toNull aheadly
154 [ -- benchIO "unfoldr" $ Ops.toNull aheadly
148 benchSrcIO aheadly "unfoldrM" Ops.sourceUnfoldrM
155 benchSrcIO aheadly "unfoldrM" Ops.sourceUnfoldrM
156+ , benchSrcIO aheadly "unfoldrM maxThreads 1"
157+ (maxThreads 1 . Ops.sourceUnfoldrM)
158+ -- XXX arbitrarily large maxRate should be the same as maxRate -1
159+ , benchSrcIO aheadly "unfoldrM maxRate 1000000"
160+ (maxRate 1000000 . Ops.sourceUnfoldrM)
161+ , benchSrcIO aheadly "unfoldrM maxBuffer 1 (1000 ops)"
162+ (maxBuffer 1 . Ops.sourceUnfoldrMN 1000)
149 -- , benchSrcIO aheadly "fromFoldable" Ops.sourceFromFoldable
163 -- , benchSrcIO aheadly "fromFoldable" Ops.sourceFromFoldable
150 , benchSrcIO aheadly "fromFoldableM" Ops.sourceFromFoldableM
164 , benchSrcIO aheadly "fromFoldableM" Ops.sourceFromFoldableM
151 -- , benchSrcIO aheadly "foldMapWith" Ops.sourceFoldMapWith
165 -- , benchSrcIO aheadly "foldMapWith" Ops.sourceFoldMapWith
benchmark/LinearOps.hs+9
@@ -80,6 +80,15 @@ sourceUnfoldrM n = S.unfoldrM step n
80 then return Nothing
80 then return Nothing
81 else return (Just (cnt, cnt + 1))
81 else return (Just (cnt, cnt + 1))
82
82
83+{-# INLINE sourceUnfoldrMN #-}
84+sourceUnfoldrMN :: (S.IsStream t, S.MonadAsync m) => Int -> Int -> t m Int
85+sourceUnfoldrMN m n = S.unfoldrM step n
86+ where
87+ step cnt =
88+ if cnt > n + m
89+ then return Nothing
90+ else return (Just (cnt, cnt + 1))
91+
83{-# INLINE sourceUnfoldrMAction #-}
92{-# INLINE sourceUnfoldrMAction #-}
84sourceUnfoldrMAction :: (S.IsStream t, S.MonadAsync m) => Int -> t m (m Int)
93sourceUnfoldrMAction :: (S.IsStream t, S.MonadAsync m) => Int -> t m (m Int)
85sourceUnfoldrMAction n = S.serially $ S.unfoldrM step n
94sourceUnfoldrMAction n = S.serially $ S.unfoldrM step n