on master help sign in
Add benchmarks for maxRate, maxThreads and maxBuffer
commitf09e741e0400ec4c954263539ea8b98948e3df2b authorHarendra Kumar <harendra.kumar@gmail.com> dateWed 8 Aug 2018, 19:28 (8 years ago) parentc602d84
2 files changed+23
benchmark/Linear.hs+14 benchmark/LinearOps.hs+9
benchmark/Linear.hs+14
@@ -126,6 +126,13 @@ main = do
126126 , bgroup "asyncly"
127127 [ -- benchIO "unfoldr" $ Ops.toNull asyncly
128128 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)
129136 -- , benchSrcIO asyncly "fromFoldable" Ops.sourceFromFoldable
130137 , benchSrcIO asyncly "fromFoldableM" Ops.sourceFromFoldableM
131138 -- , benchSrcIO asyncly "foldMapWith" Ops.sourceFoldMapWith
@@ -146,6 +153,13 @@ main = do
146153 , bgroup "aheadly"
147154 [ -- benchIO "unfoldr" $ Ops.toNull aheadly
148155 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)
149163 -- , benchSrcIO aheadly "fromFoldable" Ops.sourceFromFoldable
150164 , benchSrcIO aheadly "fromFoldableM" Ops.sourceFromFoldableM
151165 -- , benchSrcIO aheadly "foldMapWith" Ops.sourceFoldMapWith
benchmark/LinearOps.hs+9
@@ -80,6 +80,15 @@ sourceUnfoldrM n = S.unfoldrM step n
8080 then return Nothing
8181 else return (Just (cnt, cnt + 1))
8282
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+
8392{-# INLINE sourceUnfoldrMAction #-}
8493sourceUnfoldrMAction :: (S.IsStream t, S.MonadAsync m) => Int -> t m (m Int)
8594sourceUnfoldrMAction n = S.serially $ S.unfoldrM step n