on master help sign in
Remove cpp-options that control length in linear*

* This includes linear, linear-async, linear-rate * Modules removed: linear-long, linear-async-long * CPP options removed: -DLINEAR_ASYNC

commit65ed762cbc22e9e5fa45e8f92757bdf5929e5d9b authoradithyaov <adi.obilisetty@gmail.com> dateFri 3 Jan 2020, 04:06 (7 years ago) parentc2b99ed
5 files changed+526−511
benchmark/Linear.hs+279−266 benchmark/LinearAsync.hs+76−63 benchmark/LinearRate.hs+24−10 benchmark/Streamly/Benchmark/Prelude.hs+138−127 streamly.cabal+9−45
benchmark/Linear.hs+279−266
@@ -14,6 +14,8 @@ import Control.DeepSeq (NFData(..), deepseq)
1414import Data.Functor.Identity (Identity, runIdentity)
1515import System.Random (randomRIO)
1616import Data.Monoid (Last(..))
17+import System.Environment (getArgs)
18+import Text.Read (readMaybe)
1719
1820import qualified GHC.Exts as GHC
1921import qualified Streamly.Benchmark.Prelude as Ops
@@ -46,15 +48,15 @@ instance NFData Ordering where rnf = (`seq` ())
4648{-# INLINE benchIOSink #-}
4749benchIOSink
4850 :: (IsStream t, NFData b)
49− => String -> (t IO Int -> IO b) -> Benchmark
50−benchIOSink name f = bench name $ nfIO $ randomRIO (1,1) >>= f . Ops.source
51+ => Int -> String -> (t IO Int -> IO b) -> Benchmark
52+benchIOSink value name f = bench name $ nfIO $ randomRIO (1,1) >>= f . Ops.source value
5153
5254{-# INLINE benchHoistSink #-}
5355benchHoistSink
5456 :: (IsStream t, NFData b)
55− => String -> (t Identity Int -> IO b) -> Benchmark
56−benchHoistSink name f =
57− bench name $ nfIO $ randomRIO (1,1) >>= f . Ops.sourceUnfoldr
57+ => Int -> String -> (t Identity Int -> IO b) -> Benchmark
58+benchHoistSink value name f =
59+ bench name $ nfIO $ randomRIO (1,1) >>= f . Ops.sourceUnfoldr value
5860
5961-- XXX once we convert all the functions to use this we can rename this to
6062-- benchIOSink
@@ -67,8 +69,8 @@ benchIOSink1 name f = bench name $ nfIO $ randomRIO (1,1) >>= f
6769{-# INLINE benchIdentitySink #-}
6870benchIdentitySink
6971 :: (IsStream t, NFData b)
70− => String -> (t Identity Int -> Identity b) -> Benchmark
71−benchIdentitySink name f = bench name $ nf (f . Ops.sourceUnfoldr) 1
72+ => Int -> String -> (t Identity Int -> Identity b) -> Benchmark
73+benchIdentitySink value name f = bench name $ nf (f . Ops.sourceUnfoldr value) 1
7274
7375-- | Takes a source, and uses it with a default drain/fold method.
7476{-# INLINE benchIOSrc #-}
@@ -89,8 +91,8 @@ benchPure :: NFData b => String -> (Int -> a) -> (a -> b) -> Benchmark
8991benchPure name src f = bench name $ nfIO $ randomRIO (1,1) >>= return . f . src
9092
9193{-# INLINE benchPureSink #-}
92−benchPureSink :: NFData b => String -> (SerialT Identity Int -> b) -> Benchmark
93−benchPureSink name f = benchPure name Ops.sourceUnfoldr f
94+benchPureSink :: NFData b => Int -> String -> (SerialT Identity Int -> b) -> Benchmark
95+benchPureSink value name f = benchPure name (Ops.sourceUnfoldr value) f
9496
9597-- XXX once we convert all the functions to use this we can rename this to
9698-- benchPureSink
@@ -102,369 +104,380 @@ benchPureSink1 name f =
102104{-# INLINE benchPureSinkIO #-}
103105benchPureSinkIO
104106 :: NFData b
105− => String -> (SerialT Identity Int -> IO b) -> Benchmark
106−benchPureSinkIO name f =
107− bench name $ nfIO $ randomRIO (1, 1) >>= f . Ops.sourceUnfoldr
107+ => Int -> String -> (SerialT Identity Int -> IO b) -> Benchmark
108+benchPureSinkIO value name f =
109+ bench name $ nfIO $ randomRIO (1, 1) >>= f . Ops.sourceUnfoldr value
108110
109111{-# INLINE benchPureSrc #-}
110112benchPureSrc :: String -> (Int -> SerialT Identity a) -> Benchmark
111113benchPureSrc name src = benchPure name src (runIdentity . S.drain)
112114
113−mkString :: String
114−mkString = "fromList [1" ++ concat (replicate Ops.value ",1") ++ "]"
115+mkString :: Int -> String
116+mkString value = "fromList [1" ++ concat (replicate value ",1") ++ "]"
115117
116−mkListString :: String
117−mkListString = "[1" ++ concat (replicate Ops.value ",1") ++ "]"
118+mkListString :: Int -> String
119+mkListString value = "[1" ++ concat (replicate value ",1") ++ "]"
118120
119−mkList :: [Int]
120−mkList = [1..Ops.value]
121+mkList :: Int -> [Int]
122+mkList value = [1..value]
121123
122124main :: IO ()
123−main =
124− defaultMain
125+main = do
126+ -- Basement.Terminal.initialize required?
127+ args <- getArgs
128+ let (value, args') = parseValue args
129+ (cfg, extra) = parseWith defaultConfig args'
130+ runMode (mode cfg) cfg extra
125131 [ bgroup "serially"
126132 [ bgroup "pure"
127− [ benchPureSink "id" id
128− , benchPureSink1 "eqBy" Ops.eqByPure
129− , benchPureSink "==" Ops.eqInstance
130− , benchPureSink "/=" Ops.eqInstanceNotEq
131− , benchPureSink1 "cmpBy" Ops.cmpByPure
132− , benchPureSink "<" Ops.ordInstance
133− , benchPureSink "min" Ops.ordInstanceMin
134− , benchPureSrc "IsList.fromList" Ops.sourceIsList
133+ [ benchPureSink value "id" id
134+ , benchPureSink1 "eqBy" (Ops.eqByPure value)
135+ , benchPureSink value "==" Ops.eqInstance
136+ , benchPureSink value "/=" Ops.eqInstanceNotEq
137+ , benchPureSink1 "cmpBy" (Ops.cmpByPure value)
138+ , benchPureSink value "<" Ops.ordInstance
139+ , benchPureSink value "min" Ops.ordInstanceMin
140+ , benchPureSrc "IsList.fromList" (Ops.sourceIsList value)
135141 -- length is used to check for foldr/build fusion
136− , benchPureSink "length . IsList.toList" (length . GHC.toList)
137− , benchPureSrc "IsString.fromString" Ops.sourceIsString
138− , mkString `deepseq` (bench "readsPrec pure streams" $
139− nf Ops.readInstance mkString)
140− , mkString `deepseq` (bench "readsPrec Haskell lists" $
141− nf Ops.readInstanceList mkListString)
142− , benchPureSink "showsPrec pure streams" Ops.showInstance
143− , mkList `deepseq` (bench "showPrec Haskell lists" $
144− nf Ops.showInstanceList mkList)
145− , benchPureSink "foldl'" Ops.pureFoldl'
146− , benchPureSink "foldable/foldl'" Ops.foldableFoldl'
147− , benchPureSink "foldable/sum" Ops.foldableSum
148− , benchPureSinkIO "traversable/mapM" Ops.traversableMapM
142+ , benchPureSink value "length . IsList.toList" (length . GHC.toList)
143+ , benchPureSrc "IsString.fromString" (Ops.sourceIsString value)
144+ , mkString value `deepseq` (bench "readsPrec pure streams" $
145+ nf Ops.readInstance (mkString value))
146+ , mkString value `deepseq` (bench "readsPrec Haskell lists" $
147+ nf Ops.readInstanceList (mkListString value))
148+ , benchPureSink value "showsPrec pure streams" Ops.showInstance
149+ , mkList value `deepseq` (bench "showPrec Haskell lists" $
150+ nf Ops.showInstanceList (mkList value))
151+ , benchPureSink value "foldl'" Ops.pureFoldl'
152+ , benchPureSink value "foldable/foldl'" Ops.foldableFoldl'
153+ , benchPureSink value "foldable/sum" Ops.foldableSum
154+ , benchPureSinkIO value "traversable/mapM" Ops.traversableMapM
149155 ]
150156 , bgroup "generation"
151157 [ -- Most basic, barely stream continuations running
152− benchIOSrc serially "unfoldr" Ops.sourceUnfoldr
153− , benchIOSrc serially "unfoldrM" Ops.sourceUnfoldrM
154− , benchIOSrc serially "intFromTo" Ops.sourceIntFromTo
155− , benchIOSrc serially "intFromThenTo" Ops.sourceIntFromThenTo
156− , benchIOSrc serially "integerFromStep" Ops.sourceIntegerFromStep
157− , benchIOSrc serially "fracFromThenTo" Ops.sourceFracFromThenTo
158− , benchIOSrc serially "fracFromTo" Ops.sourceFracFromTo
159− , benchIOSrc serially "fromList" Ops.sourceFromList
160− , benchIOSrc serially "fromListM" Ops.sourceFromListM
158+ benchIOSrc serially "unfoldr" (Ops.sourceUnfoldr value)
159+ , benchIOSrc serially "unfoldrM" (Ops.sourceUnfoldrM value)
160+ , benchIOSrc serially "intFromTo" (Ops.sourceIntFromTo value)
161+ , benchIOSrc serially "intFromThenTo" (Ops.sourceIntFromThenTo value)
162+ , benchIOSrc serially "integerFromStep" (Ops.sourceIntegerFromStep value)
163+ , benchIOSrc serially "fracFromThenTo" (Ops.sourceFracFromThenTo value)
164+ , benchIOSrc serially "fracFromTo" (Ops.sourceFracFromTo value)
165+ , benchIOSrc serially "fromList" (Ops.sourceFromList value)
166+ , benchIOSrc serially "fromListM" (Ops.sourceFromListM value)
161167 -- These are essentially cons and consM
162− , benchIOSrc serially "fromFoldable" Ops.sourceFromFoldable
163− , benchIOSrc serially "fromFoldableM" Ops.sourceFromFoldableM
168+ , benchIOSrc serially "fromFoldable" (Ops.sourceFromFoldable value)
169+ , benchIOSrc serially "fromFoldableM" (Ops.sourceFromFoldableM value)
164170 ]
165171 , bgroup "elimination"
166172 [ bgroup "reduce"
167173 [ bgroup "IO"
168− [ benchIOSink "foldrM" Ops.foldrMReduce
169− , benchIOSink "foldl'" Ops.foldl'Reduce
170− , benchIOSink "foldl1'" Ops.foldl1'Reduce
171− , benchIOSink "foldlM'" Ops.foldlM'Reduce
174+ [ benchIOSink value "foldrM" Ops.foldrMReduce
175+ , benchIOSink value "foldl'" Ops.foldl'Reduce
176+ , benchIOSink value "foldl1'" Ops.foldl1'Reduce
177+ , benchIOSink value "foldlM'" Ops.foldlM'Reduce
172178 ]
173179 , bgroup "Identity"
174− [ benchIdentitySink "foldrM" Ops.foldrMReduce
175− , benchIdentitySink "foldl'" Ops.foldl'Reduce
176− , benchIdentitySink "foldl1'" Ops.foldl1'Reduce
177− , benchIdentitySink "foldlM'" Ops.foldlM'Reduce
180+ [ benchIdentitySink value "foldrM" Ops.foldrMReduce
181+ , benchIdentitySink value "foldl'" Ops.foldl'Reduce
182+ , benchIdentitySink value "foldl1'" Ops.foldl1'Reduce
183+ , benchIdentitySink value "foldlM'" Ops.foldlM'Reduce
178184 ]
179185 ]
180186
181187 , bgroup "build"
182188 [ bgroup "IO"
183− [ benchIOSink "foldrM" Ops.foldrMBuild
184− , benchIOSink "foldl'" Ops.foldl'Build
185− , benchIOSink "foldlM'" Ops.foldlM'Build
189+ [ benchIOSink value "foldrM" Ops.foldrMBuild
190+ , benchIOSink value "foldl'" Ops.foldl'Build
191+ , benchIOSink value "foldlM'" Ops.foldlM'Build
186192 ]
187193 , bgroup "Identity"
188− [ benchIdentitySink "foldrM" Ops.foldrMBuild
189− , benchIdentitySink "foldl'" Ops.foldl'Build
190− , benchIdentitySink "foldlM'" Ops.foldlM'Build
194+ [ benchIdentitySink value "foldrM" Ops.foldrMBuild
195+ , benchIdentitySink value "foldl'" Ops.foldl'Build
196+ , benchIdentitySink value "foldlM'" Ops.foldlM'Build
191197 ]
192198 ]
193− , benchIOSink "uncons" Ops.uncons
194− , benchIOSink "toNull" $ Ops.toNull serially
195− , benchIOSink "mapM_" Ops.mapM_
199+ , benchIOSink value "uncons" Ops.uncons
200+ , benchIOSink value "toNull" $ Ops.toNull serially
201+ , benchIOSink value "mapM_" Ops.mapM_
196202
197− , benchIOSink "init" Ops.init
198− , benchIOSink "tail" Ops.tail
199− , benchIOSink "nullHeadTail" Ops.nullHeadTail
203+ , benchIOSink value "init" Ops.init
204+ , benchIOSink value "tail" Ops.tail
205+ , benchIOSink value "nullHeadTail" Ops.nullHeadTail
200206
201207 -- this is too low and causes all benchmarks reported in ns
202− -- , benchIOSink "head" Ops.head
203− , benchIOSink "last" Ops.last
204− -- , benchIOSink "lookup" Ops.lookup
205− , benchIOSink "find" Ops.find
206− , benchIOSink "findIndex" Ops.findIndex
207− , benchIOSink "elemIndex" Ops.elemIndex
208+ -- , benchIOSink value "head" Ops.head
209+ , benchIOSink value "last" Ops.last
210+ -- , benchIOSink value "lookup" Ops.lookup
211+ , benchIOSink value "find" (Ops.find value)
212+ , benchIOSink value "findIndex" (Ops.findIndex value)
213+ , benchIOSink value "elemIndex" (Ops.elemIndex value)
208214
209215 -- this is too low and causes all benchmarks reported in ns
210− -- , benchIOSink "null" Ops.null
211− , benchIOSink "elem" Ops.elem
212− , benchIOSink "notElem" Ops.notElem
213− , benchIOSink "all" Ops.all
214− , benchIOSink "any" Ops.any
215− , benchIOSink "and" Ops.and
216− , benchIOSink "or" Ops.or
217−
218− , benchIOSink "length" Ops.length
219− , benchHoistSink "length . generally" (Ops.length . IP.generally)
220− , benchIOSink "sum" Ops.sum
221− , benchIOSink "product" Ops.product
222−
223− , benchIOSink "maximumBy" Ops.maximumBy
224− , benchIOSink "maximum" Ops.maximum
225− , benchIOSink "minimumBy" Ops.minimumBy
226− , benchIOSink "minimum" Ops.minimum
227−
228− , benchIOSink "toList" Ops.toList
229− , benchIOSink "toListRev" Ops.toListRev
216+ -- , benchIOSink value "null" Ops.null
217+ , benchIOSink value "elem" (Ops.elem value)
218+ , benchIOSink value "notElem" (Ops.notElem value)
219+ , benchIOSink value "all" (Ops.all value)
220+ , benchIOSink value "any" (Ops.any value)
221+ , benchIOSink value "and" (Ops.and value)
222+ , benchIOSink value "or" (Ops.or value)
223+
224+ , benchIOSink value "length" Ops.length
225+ , benchHoistSink value "length . generally" (Ops.length . IP.generally)
226+ , benchIOSink value "sum" Ops.sum
227+ , benchIOSink value "product" Ops.product
228+
229+ , benchIOSink value "maximumBy" Ops.maximumBy
230+ , benchIOSink value "maximum" Ops.maximum
231+ , benchIOSink value "minimumBy" Ops.minimumBy
232+ , benchIOSink value "minimum" Ops.minimum
233+
234+ , benchIOSink value "toList" Ops.toList
235+ , benchIOSink value "toListRev" Ops.toListRev
230236 ]
231237 , bgroup "folds"
232− [ benchIOSink "drain" (S.fold FL.drain)
233− , benchIOSink "drainN" (S.fold (IFL.drainN Ops.value))
234− , benchIOSink "drainWhileTrue" (S.fold (IFL.drainWhile $ (<=) Ops.maxValue))
235− , benchIOSink "drainWhileFalse" (S.fold (IFL.drainWhile $ (>=) Ops.maxValue))
236− , benchIOSink "sink" (S.fold $ Sink.toFold Sink.drain)
237− , benchIOSink "last" (S.fold FL.last)
238− , benchIOSink "lastN.1" (S.fold (IA.lastN 1))
239− , benchIOSink "lastN.10" (S.fold (IA.lastN 10))
240− , benchIOSink "lastN.Max" (S.fold (IA.lastN Ops.maxValue))
241− , benchIOSink "length" (S.fold FL.length)
242− , benchIOSink "sum" (S.fold FL.sum)
243− , benchIOSink "product" (S.fold FL.product)
244− , benchIOSink "maximumBy" (S.fold (FL.maximumBy compare))
245− , benchIOSink "maximum" (S.fold FL.maximum)
246− , benchIOSink "minimumBy" (S.fold (FL.minimumBy compare))
247− , benchIOSink "minimum" (S.fold FL.minimum)
248− , benchIOSink "mean" (\s -> S.fold FL.mean (S.map (fromIntegral :: Int -> Double) s))
249− , benchIOSink "variance" (\s -> S.fold FL.variance (S.map (fromIntegral :: Int -> Double) s))
250− , benchIOSink "stdDev" (\s -> S.fold FL.stdDev (S.map (fromIntegral :: Int -> Double) s))
251−
252− , benchIOSink "mconcat" (S.fold FL.mconcat . (S.map (Last . Just)))
253− , benchIOSink "foldMap" (S.fold (FL.foldMap (Last . Just)))
254−
255− , benchIOSink "toList" (S.fold FL.toList)
256− , benchIOSink "toListRevF" (S.fold IFL.toListRevF)
257− , benchIOSink "toStream" (S.fold IP.toStream)
258− , benchIOSink "toStreamRev" (S.fold IP.toStreamRev)
259− , benchIOSink "writeN" (S.fold (A.writeN Ops.value))
260−
261− , benchIOSink "index" (S.fold (FL.index Ops.maxValue))
262− , benchIOSink "head" (S.fold FL.head)
263− , benchIOSink "find" (S.fold (FL.find (== Ops.maxValue)))
264− , benchIOSink "findIndex" (S.fold (FL.findIndex (== Ops.maxValue)))
265− , benchIOSink "elemIndex" (S.fold (FL.elemIndex Ops.maxValue))
266−
267− , benchIOSink "null" (S.fold FL.null)
268− , benchIOSink "elem" (S.fold (FL.elem Ops.maxValue))
269− , benchIOSink "notElem" (S.fold (FL.notElem Ops.maxValue))
270− , benchIOSink "all" (S.fold (FL.all (<= Ops.maxValue)))
271− , benchIOSink "any" (S.fold (FL.any (> Ops.maxValue)))
272− , benchIOSink "and" (\s -> S.fold FL.and (S.map (<= Ops.maxValue) s))
273− , benchIOSink "or" (\s -> S.fold FL.or (S.map (> Ops.maxValue) s))
238+ [ benchIOSink value "drain" (S.fold FL.drain)
239+ , benchIOSink value "drainN" (S.fold (IFL.drainN value))
240+ , benchIOSink value "drainWhileTrue" (S.fold (IFL.drainWhile $ (<=) (value + 1)))
241+ , benchIOSink value "drainWhileFalse" (S.fold (IFL.drainWhile $ (>=) (value + 1)))
242+ , benchIOSink value "sink" (S.fold $ Sink.toFold Sink.drain)
243+ , benchIOSink value "last" (S.fold FL.last)
244+ , benchIOSink value "lastN.1" (S.fold (IA.lastN 1))
245+ , benchIOSink value "lastN.10" (S.fold (IA.lastN 10))
246+ , benchIOSink value "lastN.Max" (S.fold (IA.lastN (value + 1)))
247+ , benchIOSink value "length" (S.fold FL.length)
248+ , benchIOSink value "sum" (S.fold FL.sum)
249+ , benchIOSink value "product" (S.fold FL.product)
250+ , benchIOSink value "maximumBy" (S.fold (FL.maximumBy compare))
251+ , benchIOSink value "maximum" (S.fold FL.maximum)
252+ , benchIOSink value "minimumBy" (S.fold (FL.minimumBy compare))
253+ , benchIOSink value "minimum" (S.fold FL.minimum)
254+ , benchIOSink value "mean" (\s -> S.fold FL.mean (S.map (fromIntegral :: Int -> Double) s))
255+ , benchIOSink value "variance" (\s -> S.fold FL.variance (S.map (fromIntegral :: Int -> Double) s))
256+ , benchIOSink value "stdDev" (\s -> S.fold FL.stdDev (S.map (fromIntegral :: Int -> Double) s))
257+
258+ , benchIOSink value "mconcat" (S.fold FL.mconcat . (S.map (Last . Just)))
259+ , benchIOSink value "foldMap" (S.fold (FL.foldMap (Last . Just)))
260+
261+ , benchIOSink value "toList" (S.fold FL.toList)
262+ , benchIOSink value "toListRevF" (S.fold IFL.toListRevF)
263+ , benchIOSink value "toStream" (S.fold IP.toStream)
264+ , benchIOSink value "toStreamRev" (S.fold IP.toStreamRev)
265+ , benchIOSink value "writeN" (S.fold (A.writeN value))
266+
267+ , benchIOSink value "index" (S.fold (FL.index (value + 1)))
268+ , benchIOSink value "head" (S.fold FL.head)
269+ , benchIOSink value "find" (S.fold (FL.find (== (value + 1))))
270+ , benchIOSink value "findIndex" (S.fold (FL.findIndex (== (value + 1))))
271+ , benchIOSink value "elemIndex" (S.fold (FL.elemIndex (value + 1)))
272+
273+ , benchIOSink value "null" (S.fold FL.null)
274+ , benchIOSink value "elem" (S.fold (FL.elem (value + 1)))
275+ , benchIOSink value "notElem" (S.fold (FL.notElem (value + 1)))
276+ , benchIOSink value "all" (S.fold (FL.all (<= (value + 1))))
277+ , benchIOSink value "any" (S.fold (FL.any (> (value + 1))))
278+ , benchIOSink value "and" (\s -> S.fold FL.and (S.map (<= (value + 1)) s))
279+ , benchIOSink value "or" (\s -> S.fold FL.or (S.map (> (value + 1)) s))
274280 ]
275281 , bgroup "fold-multi-stream"
276− [ benchIOSink1 "eqBy" Ops.eqBy
277− , benchIOSink1 "cmpBy" Ops.cmpBy
278− , benchIOSink "isPrefixOf" Ops.isPrefixOf
279− , benchIOSink "isSubsequenceOf" Ops.isSubsequenceOf
280− , benchIOSink "stripPrefix" Ops.stripPrefix
282+ [ benchIOSink1 "eqBy" (Ops.eqBy value)
283+ , benchIOSink1 "cmpBy" (Ops.cmpBy value)
284+ , benchIOSink value "isPrefixOf" Ops.isPrefixOf
285+ , benchIOSink value "isSubsequenceOf" Ops.isSubsequenceOf
286+ , benchIOSink value "stripPrefix" Ops.stripPrefix
281287 ]
282288 , bgroup "folds-transforms"
283− [ benchIOSink "drain" (S.fold FL.drain)
284− , benchIOSink "lmap" (S.fold (IFL.lmap (+1) FL.drain))
285− , benchIOSink "pipe-mapM"
289+ [ benchIOSink value "drain" (S.fold FL.drain)
290+ , benchIOSink value "lmap" (S.fold (IFL.lmap (+1) FL.drain))
291+ , benchIOSink value "pipe-mapM"
286292 (S.fold (IFL.transform (Pipe.mapM (\x -> return $ x + 1)) FL.drain))
287293 ]
288294 , bgroup "folds-compositions" -- Applicative
289295 [
290− benchIOSink "all,any" (S.fold ((,) <$> FL.all (<= Ops.maxValue)
291− <*> FL.any (> Ops.maxValue)))
292− , benchIOSink "sum,length" (S.fold ((,) <$> FL.sum <*> FL.length))
296+ benchIOSink value "all,any" (S.fold ((,) <$> FL.all (<= (value + 1))
297+ <*> FL.any (> (value + 1))))
298+ , benchIOSink value "sum,length" (S.fold ((,) <$> FL.sum <*> FL.length))
293299 ]
294300 , bgroup "pipes"
295− [ benchIOSink "mapM" (Ops.transformMapM serially 1)
296− , benchIOSink "compose" (Ops.transformComposeMapM serially 1)
297− , benchIOSink "tee" (Ops.transformTeeMapM serially 1)
298− , benchIOSink "zip" (Ops.transformZipMapM serially 1)
301+ [ benchIOSink value "mapM" (Ops.transformMapM serially 1)
302+ , benchIOSink value "compose" (Ops.transformComposeMapM serially 1)
303+ , benchIOSink value "tee" (Ops.transformTeeMapM serially 1)
304+ , benchIOSink value "zip" (Ops.transformZipMapM serially 1)
299305 ]
300306 , bgroup "pipesX4"
301− [ benchIOSink "mapM" (Ops.transformMapM serially 4)
302− , benchIOSink "compose" (Ops.transformComposeMapM serially 4)
303− , benchIOSink "tee" (Ops.transformTeeMapM serially 4)
304− , benchIOSink "zip" (Ops.transformZipMapM serially 4)
307+ [ benchIOSink value "mapM" (Ops.transformMapM serially 4)
308+ , benchIOSink value "compose" (Ops.transformComposeMapM serially 4)
309+ , benchIOSink value "tee" (Ops.transformTeeMapM serially 4)
310+ , benchIOSink value "zip" (Ops.transformZipMapM serially 4)
305311 ]
306312 , bgroup "transformer"
307− [ benchIOSrc serially "evalState" Ops.evalStateT
308− , benchIOSrc serially "withState" Ops.withState
313+ [ benchIOSrc serially "evalState" (Ops.evalStateT value)
314+ , benchIOSrc serially "withState" (Ops.withState value)
309315 ]
310316 , bgroup "transformation"
311− [ benchIOSink "scanl" (Ops.scan 1)
312− , benchIOSink "scanl1'" (Ops.scanl1' 1)
313− , benchIOSink "map" (Ops.map 1)
314− , benchIOSink "fmap" (Ops.fmap 1)
315− , benchIOSink "mapM" (Ops.mapM serially 1)
316− , benchIOSink "mapMaybe" (Ops.mapMaybe 1)
317− , benchIOSink "mapMaybeM" (Ops.mapMaybeM 1)
317+ [ benchIOSink value "scanl" (Ops.scan 1)
318+ , benchIOSink value "scanl1'" (Ops.scanl1' 1)
319+ , benchIOSink value "map" (Ops.map 1)
320+ , benchIOSink value "fmap" (Ops.fmap 1)
321+ , benchIOSink value "mapM" (Ops.mapM serially 1)
322+ , benchIOSink value "mapMaybe" (Ops.mapMaybe 1)
323+ , benchIOSink value "mapMaybeM" (Ops.mapMaybeM 1)
318324 , bench "sequence" $ nfIO $ randomRIO (1,1000) >>= \n ->
319− Ops.sequence serially (Ops.sourceUnfoldrMAction n)
320− , benchIOSink "findIndices" (Ops.findIndices 1)
321− , benchIOSink "elemIndices" (Ops.elemIndices 1)
322− , benchIOSink "reverse" (Ops.reverse 1)
323− , benchIOSink "reverse'" (Ops.reverse' 1)
324− , benchIOSink "foldrS" (Ops.foldrS 1)
325− , benchIOSink "foldrSMap" (Ops.foldrSMap 1)
326− , benchIOSink "foldrT" (Ops.foldrT 1)
327− , benchIOSink "foldrTMap" (Ops.foldrTMap 1)
328− , benchIOSink "tap" (Ops.tap 1)
329− , benchIOSink "tapRate 1 second" (Ops.tapRate 1)
330− , benchIOSink "pollCounts 1 second" (Ops.pollCounts 1)
331− , benchIOSink "tapAsync" (Ops.tapAsync 1)
332− , benchIOSink "tapAsyncS" (Ops.tapAsyncS 1)
325+ Ops.sequence serially (Ops.sourceUnfoldrMAction value n)
326+ , benchIOSink value "findIndices" (Ops.findIndices value 1)
327+ , benchIOSink value "elemIndices" (Ops.elemIndices value 1)
328+ , benchIOSink value "reverse" (Ops.reverse 1)
329+ , benchIOSink value "reverse'" (Ops.reverse' 1)
330+ , benchIOSink value "foldrS" (Ops.foldrS 1)
331+ , benchIOSink value "foldrSMap" (Ops.foldrSMap 1)
332+ , benchIOSink value "foldrT" (Ops.foldrT 1)
333+ , benchIOSink value "foldrTMap" (Ops.foldrTMap 1)
334+ , benchIOSink value "tap" (Ops.tap 1)
335+ , benchIOSink value "tapRate 1 second" (Ops.tapRate 1)
336+ , benchIOSink value "pollCounts 1 second" (Ops.pollCounts 1)
337+ , benchIOSink value "tapAsync" (Ops.tapAsync 1)
338+ , benchIOSink value "tapAsyncS" (Ops.tapAsyncS 1)
333339 ]
334340 , bgroup "transformationX4"
335− [ benchIOSink "scan" (Ops.scan 4)
336− , benchIOSink "scanl1'" (Ops.scanl1' 4)
337− , benchIOSink "map" (Ops.map 4)
338− , benchIOSink "fmap" (Ops.fmap 4)
339− , benchIOSink "mapM" (Ops.mapM serially 4)
340− , benchIOSink "mapMaybe" (Ops.mapMaybe 4)
341− , benchIOSink "mapMaybeM" (Ops.mapMaybeM 4)
341+ [ benchIOSink value "scan" (Ops.scan 4)
342+ , benchIOSink value "scanl1'" (Ops.scanl1' 4)
343+ , benchIOSink value "map" (Ops.map 4)
344+ , benchIOSink value "fmap" (Ops.fmap 4)
345+ , benchIOSink value "mapM" (Ops.mapM serially 4)
346+ , benchIOSink value "mapMaybe" (Ops.mapMaybe 4)
347+ , benchIOSink value "mapMaybeM" (Ops.mapMaybeM 4)
342348 -- , bench "sequence" $ nfIO $ randomRIO (1,1000) >>= \n ->
343349 -- Ops.sequence serially (Ops.sourceUnfoldrMAction n)
344− , benchIOSink "findIndices" (Ops.findIndices 4)
345− , benchIOSink "elemIndices" (Ops.elemIndices 4)
350+ , benchIOSink value "findIndices" (Ops.findIndices value 4)
351+ , benchIOSink value "elemIndices" (Ops.elemIndices value 4)
346352 ]
347353 , bgroup "filtering"
348− [ benchIOSink "filter-even" (Ops.filterEven 1)
349− , benchIOSink "filter-all-out" (Ops.filterAllOut 1)
350− , benchIOSink "filter-all-in" (Ops.filterAllIn 1)
351− , benchIOSink "take-all" (Ops.takeAll 1)
352− , benchIOSink "takeWhile-true" (Ops.takeWhileTrue 1)
353− --, benchIOSink "takeWhileM-true" (Ops.takeWhileMTrue 1)
354− , benchIOSink "drop-one" (Ops.dropOne 1)
355− , benchIOSink "drop-all" (Ops.dropAll 1)
356− , benchIOSink "dropWhile-true" (Ops.dropWhileTrue 1)
357− --, benchIOSink "dropWhileM-true" (Ops.dropWhileMTrue 1)
358− , benchIOSink "dropWhile-false" (Ops.dropWhileFalse 1)
359− , benchIOSink "deleteBy" (Ops.deleteBy 1)
360− , benchIOSink "intersperse" (Ops.intersperse 1)
361− , benchIOSink "insertBy" (Ops.insertBy 1)
354+ [ benchIOSink value "filter-even" (Ops.filterEven 1)
355+ , benchIOSink value "filter-all-out" (Ops.filterAllOut value 1)
356+ , benchIOSink value "filter-all-in" (Ops.filterAllIn value 1)
357+ , benchIOSink value "take-all" (Ops.takeAll value 1)
358+ , benchIOSink value "takeWhile-true" (Ops.takeWhileTrue value 1)
359+ --, benchIOSink value "takeWhileM-true" (Ops.takeWhileMTrue 1)
360+ , benchIOSink value "drop-one" (Ops.dropOne 1)
361+ , benchIOSink value "drop-all" (Ops.dropAll value 1)
362+ , benchIOSink value "dropWhile-true" (Ops.dropWhileTrue value 1)
363+ --, benchIOSink value "dropWhileM-true" (Ops.dropWhileMTrue 1)
364+ , benchIOSink value "dropWhile-false" (Ops.dropWhileFalse value 1)
365+ , benchIOSink value "deleteBy" (Ops.deleteBy value 1)
366+ , benchIOSink value "intersperse" (Ops.intersperse value 1)
367+ , benchIOSink value "insertBy" (Ops.insertBy value 1)
362368 ]
363369 , bgroup "filteringX4"
364− [ benchIOSink "filter-even" (Ops.filterEven 4)
365− , benchIOSink "filter-all-out" (Ops.filterAllOut 4)
366− , benchIOSink "filter-all-in" (Ops.filterAllIn 4)
367− , benchIOSink "take-all" (Ops.takeAll 4)
368− , benchIOSink "takeWhile-true" (Ops.takeWhileTrue 4)
369− --, benchIOSink "takeWhileM-true" (Ops.takeWhileMTrue 4)
370− , benchIOSink "drop-one" (Ops.dropOne 4)
371− , benchIOSink "drop-all" (Ops.dropAll 4)
372− , benchIOSink "dropWhile-true" (Ops.dropWhileTrue 4)
373− --, benchIOSink "dropWhileM-true" (Ops.dropWhileMTrue 4)
374− , benchIOSink "dropWhile-false" (Ops.dropWhileFalse 4)
375− , benchIOSink "deleteBy" (Ops.deleteBy 4)
376− , benchIOSink "intersperse" (Ops.intersperse 4)
377− , benchIOSink "insertBy" (Ops.insertBy 4)
370+ [ benchIOSink value "filter-even" (Ops.filterEven 4)
371+ , benchIOSink value "filter-all-out" (Ops.filterAllOut value 4)
372+ , benchIOSink value "filter-all-in" (Ops.filterAllIn value 4)
373+ , benchIOSink value "take-all" (Ops.takeAll value 4)
374+ , benchIOSink value "takeWhile-true" (Ops.takeWhileTrue value 4)
375+ --, benchIOSink value "takeWhileM-true" (Ops.takeWhileMTrue 4)
376+ , benchIOSink value "drop-one" (Ops.dropOne 4)
377+ , benchIOSink value "drop-all" (Ops.dropAll value 4)
378+ , benchIOSink value "dropWhile-true" (Ops.dropWhileTrue value 4)
379+ --, benchIOSink value "dropWhileM-true" (Ops.dropWhileMTrue 4)
380+ , benchIOSink value "dropWhile-false" (Ops.dropWhileFalse value 4)
381+ , benchIOSink value "deleteBy" (Ops.deleteBy value 4)
382+ , benchIOSink value "intersperse" (Ops.intersperse value 4)
383+ , benchIOSink value "insertBy" (Ops.insertBy value 4)
378384 ]
379385 , bgroup "joining"
380− [ benchIOSrc1 "zip (2,x/2)" (Ops.zip (Ops.value `div` 2))
381− , benchIOSrc1 "zipM (2,x/2)" (Ops.zipM (Ops.value `div` 2))
382− , benchIOSrc1 "mergeBy (2,x/2)" (Ops.mergeBy (Ops.value `div` 2))
383− , benchIOSrc1 "serial (2,x/2)" (Ops.serial2 (Ops.value `div` 2))
384− , benchIOSrc1 "append (2,x/2)" (Ops.append2 (Ops.value `div` 2))
385− , benchIOSrc1 "serial (2,2,x/4)" (Ops.serial4 (Ops.value `div` 4))
386− , benchIOSrc1 "append (2,2,x/4)" (Ops.append4 (Ops.value `div` 4))
387− , benchIOSrc1 "wSerial (2,x/2)" Ops.wSerial2
388− , benchIOSrc1 "interleave (2,x/2)" Ops.interleave2
389− , benchIOSrc1 "roundRobin (2,x/2)" Ops.roundRobin2
386+ [ benchIOSrc1 "zip (2,x/2)" (Ops.zip (value `div` 2))
387+ , benchIOSrc1 "zipM (2,x/2)" (Ops.zipM (value `div` 2))
388+ , benchIOSrc1 "mergeBy (2,x/2)" (Ops.mergeBy (value `div` 2))
389+ , benchIOSrc1 "serial (2,x/2)" (Ops.serial2 (value `div` 2))
390+ , benchIOSrc1 "append (2,x/2)" (Ops.append2 (value `div` 2))
391+ , benchIOSrc1 "serial (2,2,x/4)" (Ops.serial4 (value `div` 4))
392+ , benchIOSrc1 "append (2,2,x/4)" (Ops.append4 (value `div` 4))
393+ , benchIOSrc1 "wSerial (2,x/2)" (Ops.wSerial2 value)
394+ , benchIOSrc1 "interleave (2,x/2)" (Ops.interleave2 value)
395+ , benchIOSrc1 "roundRobin (2,x/2)" (Ops.roundRobin2 value)
390396 ]
391397 , bgroup "concat-foldable"
392− [ benchIOSrc serially "foldMapWith" Ops.sourceFoldMapWith
393− , benchIOSrc serially "foldMapWithM" Ops.sourceFoldMapWithM
394− , benchIOSrc serially "foldMapM" Ops.sourceFoldMapM
395− , benchIOSrc serially "foldWithConcatMapId" Ops.sourceConcatMapId
398+ [ benchIOSrc serially "foldMapWith" (Ops.sourceFoldMapWith value)
399+ , benchIOSrc serially "foldMapWithM" (Ops.sourceFoldMapWithM value)
400+ , benchIOSrc serially "foldMapM" (Ops.sourceFoldMapM value)
401+ , benchIOSrc serially "foldWithConcatMapId" (Ops.sourceConcatMapId value)
396402 ]
397403 , bgroup "concat-serial"
398− [ benchIOSrc1 "concatMapPure (2,x/2)" (Ops.concatMapPure 2 (Ops.value `div` 2))
399− , benchIOSrc1 "concatMap (2,x/2)" (Ops.concatMap 2 (Ops.value `div` 2))
400− , benchIOSrc1 "concatMap (x/2,2)" (Ops.concatMap (Ops.value `div` 2) 2)
401− , benchIOSrc1 "concatMapRepl (x/4,4)" Ops.concatMapRepl4xN
402− , benchIOSrc1 "concatUnfoldRepl (x/4,4)" Ops.concatUnfoldRepl4xN
404+ [ benchIOSrc1 "concatMapPure (2,x/2)" (Ops.concatMapPure 2 (value `div` 2))
405+ , benchIOSrc1 "concatMap (2,x/2)" (Ops.concatMap 2 (value `div` 2))
406+ , benchIOSrc1 "concatMap (x/2,2)" (Ops.concatMap (value `div` 2) 2)
407+ , benchIOSrc1 "concatMapRepl (x/4,4)" (Ops.concatMapRepl4xN value)
408+ , benchIOSrc1 "concatUnfoldRepl (x/4,4)" (Ops.concatUnfoldRepl4xN value)
403409
404410 , benchIOSrc1 "concatMapWithSerial (2,x/2)"
405− (Ops.concatMapWithSerial 2 (Ops.value `div` 2))
411+ (Ops.concatMapWithSerial 2 (value `div` 2))
406412 , benchIOSrc1 "concatMapWithSerial (x/2,2)"
407− (Ops.concatMapWithSerial (Ops.value `div` 2) 2)
413+ (Ops.concatMapWithSerial (value `div` 2) 2)
408414
409415 , benchIOSrc1 "concatMapWithAppend (2,x/2)"
410− (Ops.concatMapWithAppend 2 (Ops.value `div` 2))
416+ (Ops.concatMapWithAppend 2 (value `div` 2))
411417 ]
412418 , bgroup "concat-interleave"
413419 [ benchIOSrc1 "concatMapWithWSerial (2,x/2)"
414− (Ops.concatMapWithWSerial 2 (Ops.value `div` 2))
420+ (Ops.concatMapWithWSerial 2 (value `div` 2))
415421 , benchIOSrc1 "concatMapWithWSerial (x/2,2)"
416− (Ops.concatMapWithWSerial (Ops.value `div` 2) 2)
422+ (Ops.concatMapWithWSerial (value `div` 2) 2)
417423 , benchIOSrc1 "concatUnfoldInterleaveRepl (x/4,4)"
418− Ops.concatUnfoldInterleaveRepl4xN
424+ (Ops.concatUnfoldInterleaveRepl4xN value)
419425 , benchIOSrc1 "concatUnfoldRoundrobinRepl (x/4,4)"
420− Ops.concatUnfoldRoundrobinRepl4xN
426+ (Ops.concatUnfoldRoundrobinRepl4xN value)
421427 ]
422428 -- scanl-map and foldl-map are equivalent to the scan and fold in the foldl
423429 -- library. If scan/fold followed by a map is efficient enough we may not
424430 -- need monolithic implementations of these.
425431 , bgroup "mixed"
426− [ benchIOSink "scanl-map" (Ops.scanMap 1)
427− , benchIOSink "foldl-map" Ops.foldl'ReduceMap
428− , benchIOSink "sum-product-fold" Ops.sumProductFold
429− , benchIOSink "sum-product-scan" Ops.sumProductScan
432+ [ benchIOSink value "scanl-map" (Ops.scanMap 1)
433+ , benchIOSink value "foldl-map" Ops.foldl'ReduceMap
434+ , benchIOSink value "sum-product-fold" Ops.sumProductFold
435+ , benchIOSink value "sum-product-scan" Ops.sumProductScan
430436 ]
431437 , bgroup "mixedX4"
432− [ benchIOSink "scan-map" (Ops.scanMap 4)
433− , benchIOSink "drop-map" (Ops.dropMap 4)
434− , benchIOSink "drop-scan" (Ops.dropScan 4)
435− , benchIOSink "take-drop" (Ops.takeDrop 4)
436− , benchIOSink "take-scan" (Ops.takeScan 4)
437− , benchIOSink "take-map" (Ops.takeMap 4)
438− , benchIOSink "filter-drop" (Ops.filterDrop 4)
439− , benchIOSink "filter-take" (Ops.filterTake 4)
440− , benchIOSink "filter-scan" (Ops.filterScan 4)
441− , benchIOSink "filter-scanl1" (Ops.filterScanl1 4)
442− , benchIOSink "filter-map" (Ops.filterMap 4)
438+ [ benchIOSink value "scan-map" (Ops.scanMap 4)
439+ , benchIOSink value "drop-map" (Ops.dropMap 4)
440+ , benchIOSink value "drop-scan" (Ops.dropScan 4)
441+ , benchIOSink value "take-drop" (Ops.takeDrop value 4)
442+ , benchIOSink value "take-scan" (Ops.takeScan value 4)
443+ , benchIOSink value "take-map" (Ops.takeMap value 4)
444+ , benchIOSink value "filter-drop" (Ops.filterDrop value 4)
445+ , benchIOSink value "filter-take" (Ops.filterTake value 4)
446+ , benchIOSink value "filter-scan" (Ops.filterScan 4)
447+ , benchIOSink value "filter-scanl1" (Ops.filterScanl1 4)
448+ , benchIOSink value "filter-map" (Ops.filterMap value 4)
443449 ]
444450 , bgroup "iterated"
445451 [ benchIOSrc serially "mapM" Ops.iterateMapM
446452 , benchIOSrc serially "scan(1/100)" Ops.iterateScan
447453 , benchIOSrc serially "scanl1(1/100)" Ops.iterateScanl1
448454 , benchIOSrc serially "filterEven" Ops.iterateFilterEven
449− , benchIOSrc serially "takeAll" Ops.iterateTakeAll
455+ , benchIOSrc serially "takeAll" (Ops.iterateTakeAll value)
450456 , benchIOSrc serially "dropOne" Ops.iterateDropOne
451− , benchIOSrc serially "dropWhileFalse" Ops.iterateDropWhileFalse
452− , benchIOSrc serially "dropWhileTrue" Ops.iterateDropWhileTrue
457+ , benchIOSrc serially "dropWhileFalse" (Ops.iterateDropWhileFalse value)
458+ , benchIOSrc serially "dropWhileTrue" (Ops.iterateDropWhileTrue value)
453459 ]
454460 ]
455461 , bgroup "wSerially"
456462 [ bgroup "transformation"
457− [ benchIOSink "fmap" $ Ops.fmap' wSerially 1
463+ [ benchIOSink value "fmap" $ Ops.fmap' wSerially 1
458464 ]
459465 ]
460466 , bgroup "zipSerially"
461467 [ bgroup "transformation"
462− [ benchIOSink "fmap" $ Ops.fmap' zipSerially 1
468+ [ benchIOSink value "fmap" $ Ops.fmap' zipSerially 1
463469 ]
464470 ]
465471 , bgroup "zipAsyncly"
466472 [ bgroup "transformation"
467− [ benchIOSink "fmap" $ Ops.fmap' zipAsyncly 1
473+ [ benchIOSink value "fmap" $ Ops.fmap' zipAsyncly 1
468474 ]
469475 ]
470476 ]
477+ where
478+ defaultValue = 100000
479+ parseValue [] = (defaultValue, [])
480+ parseValue a@(x:xs) =
481+ case (readMaybe x :: Maybe Int) of
482+ Just value -> (value, xs)
483+ Nothing -> (defaultValue, a)
benchmark/LinearAsync.hs+76−63
@@ -9,6 +9,8 @@
99import Control.DeepSeq (NFData)
1010-- import Data.Functor.Identity (Identity, runIdentity)
1111import System.Random (randomRIO)
12+import Text.Read (readMaybe)
13+import System.Environment (getArgs)
1214import qualified Streamly.Benchmark.Prelude as Ops
1315
1416import Streamly
@@ -19,8 +21,8 @@ import Gauge
1921--
2022-- | Takes a fold method, and uses it with a default source.
2123{-# INLINE benchIO #-}
22−benchIO :: (IsStream t, NFData b) => String -> (t IO Int -> IO b) -> Benchmark
23−benchIO name f = bench name $ nfIO $ randomRIO (1,1) >>= f . Ops.source
24+benchIO :: (IsStream t, NFData b) => Int -> String -> (t IO Int -> IO b) -> Benchmark
25+benchIO value name f = bench name $ nfIO $ randomRIO (1,1) >>= f . Ops.source value
2426
2527-- | Takes a source, and uses it with a default drain/fold method.
2628{-# INLINE benchSrcIO #-}
@@ -42,94 +44,105 @@ _benchId name f = bench name $ nf (runIdentity . f) (Ops.source 10)
4244-}
4345
4446main :: IO ()
45−main =
46− defaultMainWith (defaultConfig
47− { timeLimit = Just 1
48− , minDuration = 0
49−#ifdef LONG_BENCHMARKS
50− , includeFirstIter = True
51−#endif
52− })
47+main = do
48+ -- Basement.Terminal.initialize required?
49+ args <- getArgs
50+ let (value, args') = parseValue args
51+ (cfg, extra) = parseWith (newConfig value) args'
52+ runMode (mode cfg) cfg extra
5353 [ bgroup "asyncly"
54− [ benchSrcIO asyncly "unfoldr" Ops.sourceUnfoldr
55− , benchSrcIO asyncly "unfoldrM" Ops.sourceUnfoldrM
56− , benchSrcIO asyncly "fromFoldable" Ops.sourceFromFoldable
57− , benchSrcIO asyncly "fromFoldableM" Ops.sourceFromFoldableM
58− , benchSrcIO asyncly "foldMapWith" Ops.sourceFoldMapWith
59− , benchSrcIO asyncly "foldMapWithM" Ops.sourceFoldMapWithM
60− , benchSrcIO asyncly "foldMapM" Ops.sourceFoldMapM
61− , benchIO "map" $ Ops.map' asyncly 1
62− , benchIO "fmap" $ Ops.fmap' asyncly 1
63− , benchIO "mapM" $ Ops.mapM asyncly 1
54+ [ benchSrcIO asyncly "unfoldr" (Ops.sourceUnfoldr value)
55+ , benchSrcIO asyncly "unfoldrM" (Ops.sourceUnfoldrM value)
56+ , benchSrcIO asyncly "fromFoldable" (Ops.sourceFromFoldable value)
57+ , benchSrcIO asyncly "fromFoldableM" (Ops.sourceFromFoldableM value)
58+ , benchSrcIO asyncly "foldMapWith" (Ops.sourceFoldMapWith value)
59+ , benchSrcIO asyncly "foldMapWithM" (Ops.sourceFoldMapWithM value)
60+ , benchSrcIO asyncly "foldMapM" (Ops.sourceFoldMapM value)
61+ , benchIO value "map" $ Ops.map' asyncly 1
62+ , benchIO value "fmap" $ Ops.fmap' asyncly 1
63+ , benchIO value "mapM" $ Ops.mapM asyncly 1
6464 , benchSrcIO asyncly "unfoldrM maxThreads 1"
65− (maxThreads 1 . Ops.sourceUnfoldrM)
65+ (maxThreads 1 . Ops.sourceUnfoldrM value)
6666 , benchSrcIO asyncly "unfoldrM maxBuffer 1 (x/10 ops)"
67− (maxBuffer 1 . Ops.sourceUnfoldrMN (Ops.value `div` 10))
67+ (maxBuffer 1 . Ops.sourceUnfoldrMN (value `div` 10))
6868 , benchMonadicSrcIO "concatMapWith (2,x/2)"
69− (Ops.concatStreamsWith async 2 (Ops.value `div` 2))
69+ (Ops.concatStreamsWith async 2 (value `div` 2))
7070 , benchMonadicSrcIO "concatMapWith (x/2,2)"
71− (Ops.concatStreamsWith async (Ops.value `div` 2) 2)
71+ (Ops.concatStreamsWith async (value `div` 2) 2)
7272 ]
7373 , bgroup "wAsyncly"
74− [ benchSrcIO wAsyncly "unfoldr" Ops.sourceUnfoldr
75− , benchSrcIO wAsyncly "unfoldrM" Ops.sourceUnfoldrM
76− , benchSrcIO wAsyncly "fromFoldable" Ops.sourceFromFoldable
77− , benchSrcIO wAsyncly "fromFoldableM" Ops.sourceFromFoldableM
78− , benchSrcIO wAsyncly "foldMapWith" Ops.sourceFoldMapWith
79− , benchSrcIO wAsyncly "foldMapWithM" Ops.sourceFoldMapWithM
80− , benchSrcIO wAsyncly "foldMapM" Ops.sourceFoldMapM
81− , benchIO "map" $ Ops.map' wAsyncly 1
82− , benchIO "fmap" $ Ops.fmap' wAsyncly 1
83− , benchIO "mapM" $ Ops.mapM wAsyncly 1
74+ [ benchSrcIO wAsyncly "unfoldr" (Ops.sourceUnfoldr value)
75+ , benchSrcIO wAsyncly "unfoldrM" (Ops.sourceUnfoldrM value)
76+ , benchSrcIO wAsyncly "fromFoldable" (Ops.sourceFromFoldable value)
77+ , benchSrcIO wAsyncly "fromFoldableM" (Ops.sourceFromFoldableM value)
78+ , benchSrcIO wAsyncly "foldMapWith" (Ops.sourceFoldMapWith value)
79+ , benchSrcIO wAsyncly "foldMapWithM" (Ops.sourceFoldMapWithM value)
80+ , benchSrcIO wAsyncly "foldMapM" (Ops.sourceFoldMapM value)
81+ , benchIO value "map" $ Ops.map' wAsyncly 1
82+ , benchIO value "fmap" $ Ops.fmap' wAsyncly 1
83+ , benchIO value "mapM" $ Ops.mapM wAsyncly 1
8484 , benchMonadicSrcIO "concatMapWith (2,x/2)"
85− (Ops.concatStreamsWith wAsync 2 (Ops.value `div` 2))
85+ (Ops.concatStreamsWith wAsync 2 (value `div` 2))
8686 , benchMonadicSrcIO "concatMapWith (x/2,2)"
87− (Ops.concatStreamsWith wAsync (Ops.value `div` 2) 2)
87+ (Ops.concatStreamsWith wAsync (value `div` 2) 2)
8888 ]
8989 -- unfoldr and fromFoldable are always serial and thereofore the same for
9090 -- all stream types.
9191 , bgroup "aheadly"
92− [ benchSrcIO aheadly "unfoldr" Ops.sourceUnfoldr
93− , benchSrcIO aheadly "unfoldrM" Ops.sourceUnfoldrM
94− , benchSrcIO aheadly "fromFoldableM" Ops.sourceFromFoldableM
92+ [ benchSrcIO aheadly "unfoldr" (Ops.sourceUnfoldr value)
93+ , benchSrcIO aheadly "unfoldrM" (Ops.sourceUnfoldrM value)
94+ , benchSrcIO aheadly "fromFoldableM" (Ops.sourceFromFoldableM value)
9595 -- , benchSrcIO aheadly "foldMapWith" Ops.sourceFoldMapWith
96− , benchSrcIO aheadly "foldMapWithM" Ops.sourceFoldMapWithM
97− , benchSrcIO aheadly "foldMapM" Ops.sourceFoldMapM
98− , benchIO "map" $ Ops.map' aheadly 1
99− , benchIO "fmap" $ Ops.fmap' aheadly 1
100− , benchIO "mapM" $ Ops.mapM aheadly 1
96+ , benchSrcIO aheadly "foldMapWithM" (Ops.sourceFoldMapWithM value)
97+ , benchSrcIO aheadly "foldMapM" (Ops.sourceFoldMapM value)
98+ , benchIO value "map" $ Ops.map' aheadly 1
99+ , benchIO value "fmap" $ Ops.fmap' aheadly 1
100+ , benchIO value "mapM" $ Ops.mapM aheadly 1
101101 , benchSrcIO aheadly "unfoldrM maxThreads 1"
102− (maxThreads 1 . Ops.sourceUnfoldrM)
102+ (maxThreads 1 . Ops.sourceUnfoldrM value)
103103 , benchSrcIO aheadly "unfoldrM maxBuffer 1 (x/10 ops)"
104− (maxBuffer 1 . Ops.sourceUnfoldrMN (Ops.value `div` 10))
104+ (maxBuffer 1 . Ops.sourceUnfoldrMN (value `div` 10))
105105 -- , benchSrcIO aheadly "fromFoldable" Ops.sourceFromFoldable
106106 , benchMonadicSrcIO "concatMapWith (2,x/2)"
107− (Ops.concatStreamsWith ahead 2 (Ops.value `div` 2))
107+ (Ops.concatStreamsWith ahead 2 (value `div` 2))
108108 , benchMonadicSrcIO "concatMapWith (x/2,2)"
109− (Ops.concatStreamsWith ahead (Ops.value `div` 2) 2)
109+ (Ops.concatStreamsWith ahead (value `div` 2) 2)
110110 ]
111111 -- XXX need to use smaller streams to finish in reasonable time
112112 , bgroup "parallely"
113− [ benchSrcIO parallely "unfoldr" Ops.sourceUnfoldr
114− , benchSrcIO parallely "unfoldrM" Ops.sourceUnfoldrM
113+ [ benchSrcIO parallely "unfoldr" (Ops.sourceUnfoldr value)
114+ , benchSrcIO parallely "unfoldrM" (Ops.sourceUnfoldrM value)
115115 --, benchSrcIO parallely "fromFoldable" Ops.sourceFromFoldable
116− , benchSrcIO parallely "fromFoldableM" Ops.sourceFromFoldableM
116+ , benchSrcIO parallely "fromFoldableM" (Ops.sourceFromFoldableM value)
117117 -- , benchSrcIO parallely "foldMapWith" Ops.sourceFoldMapWith
118− , benchSrcIO parallely "foldMapWithM" Ops.sourceFoldMapWithM
119− , benchSrcIO parallely "foldMapM" Ops.sourceFoldMapM
120− , benchIO "map" $ Ops.map' parallely 1
121− , benchIO "fmap" $ Ops.fmap' parallely 1
122− , benchIO "mapM" $ Ops.mapM parallely 1
118+ , benchSrcIO parallely "foldMapWithM" (Ops.sourceFoldMapWithM value)
119+ , benchSrcIO parallely "foldMapM" (Ops.sourceFoldMapM value)
120+ , benchIO value "map" $ Ops.map' parallely 1
121+ , benchIO value "fmap" $ Ops.fmap' parallely 1
122+ , benchIO value "mapM" $ Ops.mapM parallely 1
123123 -- Zip has only one parallel flavor
124− , benchIO "zip" Ops.zipAsync
125− , benchIO "zipM" Ops.zipAsyncM
126− , benchIO "zipAp" Ops.zipAsyncAp
124+ , benchIO value "zip" Ops.zipAsync
125+ , benchIO value "zipM" Ops.zipAsyncM
126+ , benchIO value "zipAp" Ops.zipAsyncAp
127127 -- Parallel stages in a pipeline
128− , benchIO "parAppMap" Ops.parAppMap
129− , benchIO "parAppSum" Ops.parAppSum
128+ , benchIO value "parAppMap" Ops.parAppMap
129+ , benchIO value "parAppSum" Ops.parAppSum
130130 , benchMonadicSrcIO "concatMapWith (2,x/2)"
131− (Ops.concatStreamsWith parallel 2 (Ops.value `div` 2))
131+ (Ops.concatStreamsWith parallel 2 (value `div` 2))
132132 , benchMonadicSrcIO "concatMapWith (x/10,10)"
133− (Ops.concatStreamsWith parallel (Ops.value `div` 10) 10)
133+ (Ops.concatStreamsWith parallel (value `div` 10) 10)
134134 ]
135135 ]
136+ where
137+ defaultValue = 10000
138+ parseValue [] = (defaultValue, [])
139+ parseValue a@(x:xs) =
140+ case (readMaybe x :: Maybe Int) of
141+ Just value -> (value, xs)
142+ Nothing -> (defaultValue, a)
143+ newConfig value =
144+ defaultConfig
145+ { timeLimit = Just 1
146+ , minDuration = 0
147+ , includeFirstIter = value >= 10000000
148+ }
benchmark/LinearRate.hs+24−10
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
12-- |
23-- Module : Main
34-- Copyright : (c) 2018 Harendra Kumar
@@ -11,6 +12,8 @@
1112-- import Data.Functor.Identity (Identity, runIdentity)
1213import System.Random (randomRIO)
1314import qualified Streamly.Benchmark.Prelude as Ops
15+import System.Environment (getArgs)
16+import Text.Read (readMaybe)
1417
1518import Streamly
1619import Gauge
@@ -31,30 +34,41 @@ _benchId name f = bench name $ nf (runIdentity . f) (Ops.source 10)
3134-}
3235
3336main :: IO ()
34−main =
35− defaultMain
37+main = do
38+ -- Basement.Terminal.initialize required?
39+ args <- getArgs
40+ let (value, args') = parseValue args
41+ (cfg, extra) = parseWith defaultConfig args'
42+ runMode (mode cfg) cfg extra
3643 -- XXX arbitrarily large rate should be the same as rate Nothing
3744 [ bgroup "avgrate"
3845 [ bgroup "asyncly"
3946 [ -- benchIO "unfoldr" $ Ops.toNull asyncly
40− benchSrcIO asyncly "unfoldrM" Ops.sourceUnfoldrM
47+ benchSrcIO asyncly "unfoldrM" (Ops.sourceUnfoldrM value)
4148 , benchSrcIO asyncly "unfoldrM/Nothing"
42− (rate Nothing . Ops.sourceUnfoldrM)
49+ (rate Nothing . Ops.sourceUnfoldrM value)
4350 , benchSrcIO asyncly "unfoldrM/1,000,000"
44− (avgRate 1000000 . Ops.sourceUnfoldrM)
51+ (avgRate 1000000 . Ops.sourceUnfoldrM value)
4552 , benchSrcIO asyncly "unfoldrM/3,000,000"
46− (avgRate 3000000 . Ops.sourceUnfoldrM)
53+ (avgRate 3000000 . Ops.sourceUnfoldrM value)
4754 , benchSrcIO asyncly "unfoldrM/10,000,000/maxThreads1"
48− (maxThreads 1 . avgRate 10000000 . Ops.sourceUnfoldrM)
55+ (maxThreads 1 . avgRate 10000000 . Ops.sourceUnfoldrM value)
4956 , benchSrcIO asyncly "unfoldrM/10,000,000"
50− (avgRate 10000000 . Ops.sourceUnfoldrM)
57+ (avgRate 10000000 . Ops.sourceUnfoldrM value)
5158 , benchSrcIO asyncly "unfoldrM/20,000,000"
52− (avgRate 20000000 . Ops.sourceUnfoldrM)
59+ (avgRate 20000000 . Ops.sourceUnfoldrM value)
5360 ]
5461 , bgroup "aheadly"
5562 [
5663 benchSrcIO aheadly "unfoldrM/1,000,000"
57− (avgRate 1000000 . Ops.sourceUnfoldrM)
64+ (avgRate 1000000 . Ops.sourceUnfoldrM value)
5865 ]
5966 ]
6067 ]
68+ where
69+ defaultValue = 100000
70+ parseValue [] = (defaultValue, [])
71+ parseValue a@(x:xs) =
72+ case (readMaybe x :: Maybe Int) of
73+ Just value -> (value, xs)
74+ Nothing -> (defaultValue, a)
benchmark/Streamly/Benchmark/Prelude.hs+138−127
@@ -35,7 +35,7 @@ import Prelude
3535 (Monad, Int, (+), ($), (.), return, fmap, even, (>), (<=), (==), (>=),
3636 subtract, undefined, Maybe(..), odd, Bool, not, (>>=), mapM_, curry,
3737 maxBound, div, IO, compare, Double, fromIntegral, Integer, (<$>),
38− (<*>), flip, (**), (/))
38+ (<*>), flip)
3939import qualified Prelude as P
4040import qualified Data.Foldable as F
4141import qualified GHC.Exts as GHC
@@ -54,18 +54,8 @@ import qualified Streamly.Internal.Data.Unfold as UF
5454import qualified Streamly.Internal.Data.Pipe as Pipe
5555import qualified Streamly.Internal.Data.Stream.Parallel as Par
5656
57−value, maxValue, value2 :: Int
58−
59−-- To detect memory leak issues we need larger streams
60−#ifdef LONG_BENCHMARKS
61−value = 10000000
62−#elif defined(LINEAR_ASYNC)
63−value = 10000
64−#else
65−value = 100000
66−#endif
67−maxValue = value + 1
68−value2 = P.round (P.fromIntegral value**(1/2::P.Double)) -- double nested loop
57+-- To detect memory leak issues use larger streams.
58+-- See Note in .cabal file on how to generate streams of specific size.
6959
7060type Stream m a = S.SerialT m a
7161
@@ -76,33 +66,33 @@ type Stream m a = S.SerialT m a
7666-- enumerate
7767
7868{-# INLINE sourceIntFromTo #-}
79−sourceIntFromTo :: (Monad m, S.IsStream t) => Int -> t m Int
80−sourceIntFromTo n = S.enumerateFromTo n (n + value)
69+sourceIntFromTo :: (Monad m, S.IsStream t) => Int -> Int -> t m Int
70+sourceIntFromTo value n = S.enumerateFromTo n (n + value)
8171
8272{-# INLINE sourceIntFromThenTo #-}
83−sourceIntFromThenTo :: (Monad m, S.IsStream t) => Int -> t m Int
84−sourceIntFromThenTo n = S.enumerateFromThenTo n (n + 1) (n + value)
73+sourceIntFromThenTo :: (Monad m, S.IsStream t) => Int -> Int -> t m Int
74+sourceIntFromThenTo value n = S.enumerateFromThenTo n (n + 1) (n + value)
8575
8676{-# INLINE sourceFracFromTo #-}
87−sourceFracFromTo :: (Monad m, S.IsStream t) => Int -> t m Double
88−sourceFracFromTo n =
77+sourceFracFromTo :: (Monad m, S.IsStream t) => Int -> Int -> t m Double
78+sourceFracFromTo value n =
8979 S.enumerateFromTo (fromIntegral n) (fromIntegral (n + value))
9080
9181{-# INLINE sourceFracFromThenTo #-}
92−sourceFracFromThenTo :: (Monad m, S.IsStream t) => Int -> t m Double
93−sourceFracFromThenTo n = S.enumerateFromThenTo (fromIntegral n)
82+sourceFracFromThenTo :: (Monad m, S.IsStream t) => Int -> Int -> t m Double
83+sourceFracFromThenTo value n = S.enumerateFromThenTo (fromIntegral n)
9484 (fromIntegral n + 1.0001) (fromIntegral (n + value))
9585
9686{-# INLINE sourceIntegerFromStep #-}
97−sourceIntegerFromStep :: (Monad m, S.IsStream t) => Int -> t m Integer
98−sourceIntegerFromStep n =
87+sourceIntegerFromStep :: (Monad m, S.IsStream t) => Int -> Int -> t m Integer
88+sourceIntegerFromStep value n =
9989 S.take value $ S.enumerateFromThen (fromIntegral n) (fromIntegral n + 1)
10090
10191-- unfoldr
10292
10393{-# INLINE sourceUnfoldr #-}
104−sourceUnfoldr :: (Monad m, S.IsStream t) => Int -> t m Int
105−sourceUnfoldr n = S.unfoldr step n
94+sourceUnfoldr :: (Monad m, S.IsStream t) => Int -> Int -> t m Int
95+sourceUnfoldr value n = S.unfoldr step n
10696 where
10797 step cnt =
10898 if cnt > n + value
@@ -119,8 +109,8 @@ sourceUnfoldrN upto start = S.unfoldr step start
119109 else Just (cnt, cnt + 1)
120110
121111{-# INLINE sourceUnfoldrM #-}
122−sourceUnfoldrM :: (S.IsStream t, S.MonadAsync m) => Int -> t m Int
123−sourceUnfoldrM n = S.unfoldrM step n
112+sourceUnfoldrM :: (S.IsStream t, S.MonadAsync m) => Int -> Int -> t m Int
113+sourceUnfoldrM value n = S.unfoldrM step n
124114 where
125115 step cnt =
126116 if cnt > n + value
@@ -128,8 +118,8 @@ sourceUnfoldrM n = S.unfoldrM step n
128118 else return (Just (cnt, cnt + 1))
129119
130120{-# INLINE source #-}
131−source :: (S.MonadAsync m, S.IsStream t) => Int -> t m Int
132−source n = sourceUnfoldrM n
121+source :: (S.MonadAsync m, S.IsStream t) => Int -> Int -> t m Int
122+source = sourceUnfoldrM
133123
134124{-# INLINE sourceUnfoldrMN #-}
135125sourceUnfoldrMN :: (S.IsStream t, S.MonadAsync m) => Int -> Int -> t m Int
@@ -141,8 +131,8 @@ sourceUnfoldrMN upto start = S.unfoldrM step start
141131 else return (Just (cnt, cnt + 1))
142132
143133{-# INLINE sourceUnfoldrMAction #-}
144−sourceUnfoldrMAction :: (S.IsStream t, S.MonadAsync m) => Int -> t m (m Int)
145−sourceUnfoldrMAction n = S.serially $ S.unfoldrM step n
134+sourceUnfoldrMAction :: (S.IsStream t, S.MonadAsync m) => Int -> Int -> t m (m Int)
135+sourceUnfoldrMAction value n = S.serially $ S.unfoldrM step n
146136 where
147137 step cnt =
148138 if cnt > n + value
@@ -152,40 +142,40 @@ sourceUnfoldrMAction n = S.serially $ S.unfoldrM step n
152142-- fromIndices
153143
154144{-# INLINE sourceFromIndices #-}
155−sourceFromIndices :: (Monad m, S.IsStream t) => Int -> t m Int
156−sourceFromIndices n = S.take value $ S.fromIndices (+ n)
145+sourceFromIndices :: (Monad m, S.IsStream t) => Int -> Int -> t m Int
146+sourceFromIndices value n = S.take value $ S.fromIndices (+ n)
157147
158148{-# INLINE sourceFromIndicesM #-}
159−sourceFromIndicesM :: (S.MonadAsync m, S.IsStream t) => Int -> t m Int
160−sourceFromIndicesM n = S.take value $ S.fromIndicesM (Prelude.fmap return (+ n))
149+sourceFromIndicesM :: (S.MonadAsync m, S.IsStream t) => Int -> Int -> t m Int
150+sourceFromIndicesM value n = S.take value $ S.fromIndicesM (Prelude.fmap return (+ n))
161151
162152-- fromList
163153
164154{-# INLINE sourceFromList #-}
165−sourceFromList :: (Monad m, S.IsStream t) => Int -> t m Int
166−sourceFromList n = S.fromList [n..n+value]
155+sourceFromList :: (Monad m, S.IsStream t) => Int -> Int -> t m Int
156+sourceFromList value n = S.fromList [n..n+value]
167157
168158{-# INLINE sourceFromListM #-}
169−sourceFromListM :: (S.MonadAsync m, S.IsStream t) => Int -> t m Int
170−sourceFromListM n = S.fromListM (Prelude.fmap return [n..n+value])
159+sourceFromListM :: (S.MonadAsync m, S.IsStream t) => Int -> Int -> t m Int
160+sourceFromListM value n = S.fromListM (Prelude.fmap return [n..n+value])
171161
172162{-# INLINE sourceIsList #-}
173−sourceIsList :: Int -> S.SerialT Identity Int
174−sourceIsList n = GHC.fromList [n..n+value]
163+sourceIsList :: Int -> Int -> S.SerialT Identity Int
164+sourceIsList value n = GHC.fromList [n..n+value]
175165
176166{-# INLINE sourceIsString #-}
177−sourceIsString :: Int -> S.SerialT Identity P.Char
178−sourceIsString n = GHC.fromString (P.replicate (n + value) 'a')
167+sourceIsString :: Int -> Int -> S.SerialT Identity P.Char
168+sourceIsString value n = GHC.fromString (P.replicate (n + value) 'a')
179169
180170-- fromFoldable
181171
182172{-# INLINE sourceFromFoldable #-}
183−sourceFromFoldable :: S.IsStream t => Int -> t m Int
184−sourceFromFoldable n = S.fromFoldable [n..n+value]
173+sourceFromFoldable :: S.IsStream t => Int -> Int -> t m Int
174+sourceFromFoldable value n = S.fromFoldable [n..n+value]
185175
186176{-# INLINE sourceFromFoldableM #-}
187−sourceFromFoldableM :: (S.IsStream t, S.MonadAsync m) => Int -> t m Int
188−sourceFromFoldableM n = S.fromFoldableM (Prelude.fmap return [n..n+value])
177+sourceFromFoldableM :: (S.IsStream t, S.MonadAsync m) => Int -> Int -> t m Int
178+sourceFromFoldableM value n = S.fromFoldableM (Prelude.fmap return [n..n+value])
189179
190180-------------------------------------------------------------------------------
191181-- Elimination
@@ -206,9 +196,12 @@ toList :: Monad m => Stream m Int -> m [Int]
206196{-# INLINE findIndex #-}
207197{-# INLINE elemIndex #-}
208198{-# INLINE foldl1'Reduce #-}
209−head, last, minimum, maximum, find, findIndex, elemIndex, foldl1'Reduce
199+head, last, minimum, maximum, foldl1'Reduce
210200 :: Monad m => Stream m Int -> m (Maybe Int)
211201
202+find, findIndex, elemIndex
203+ :: Monad m => Int -> Stream m Int -> m (Maybe Int)
204+
212205{-# INLINE minimumBy #-}
213206{-# INLINE maximumBy #-}
214207minimumBy, maximumBy :: Monad m => Stream m Int -> m (Maybe Int)
@@ -238,7 +231,9 @@ foldrMBuild, foldl'Build, foldlM'Build
238231{-# INLINE null #-}
239232{-# INLINE elem #-}
240233{-# INLINE notElem #-}
241−null, elem, notElem, all, any, and, or :: Monad m => Stream m Int -> m Bool
234+null :: Monad m => Stream m Int -> m Bool
235+
236+elem, notElem, all, any, and, or :: Monad m => Int -> Stream m Int -> m Bool
242237
243238{-# INLINE toNull #-}
244239toNull :: Monad m => (t m a -> S.SerialT m a) -> t m a -> m ()
@@ -291,16 +286,16 @@ foldlM'Reduce = S.foldlM' (\xs a -> return $ a + xs) 0
291286last = S.last
292287null = S.null
293288head = S.head
294−elem = S.elem maxValue
295−notElem = S.notElem maxValue
289+elem value = S.elem (value + 1)
290+notElem value = S.notElem (value + 1)
296291length = S.length
297−all = S.all (<= maxValue)
298−any = S.any (> maxValue)
299−and = S.and . S.map (<= maxValue)
300−or = S.or . S.map (> maxValue)
301−find = S.find (== maxValue)
302−findIndex = S.findIndex (== maxValue)
303−elemIndex = S.elemIndex maxValue
292+all value = S.all (<= (value + 1))
293+any value = S.any (> (value + 1))
294+and value = S.and . S.map (<= (value + 1))
295+or value = S.or . S.map (> (value + 1))
296+find value = S.find (== (value + 1))
297+findIndex value = S.findIndex (== (value + 1))
298+elemIndex value = S.elemIndex (value + 1)
304299maximum = S.maximum
305300minimum = S.minimum
306301sum = S.sum
@@ -368,17 +363,24 @@ composeN' n f =
368363{-# INLINE foldrSMap #-}
369364{-# INLINE foldrT #-}
370365{-# INLINE foldrTMap #-}
371−scan, scanl1', map, fmap, mapMaybe, filterEven, filterAllOut,
372− filterAllIn, takeOne, takeAll, takeWhileTrue, takeWhileMTrue, dropOne,
373− dropAll, dropWhileTrue, dropWhileMTrue, dropWhileFalse,
374− findIndices, elemIndices, insertBy, deleteBy, reverse, reverse',
366+scan, scanl1', map, fmap, mapMaybe, filterEven,
367+ takeOne, dropOne,
368+ reverse, reverse',
375369 foldrS, foldrSMap, foldrT, foldrTMap
376370 :: MonadIO m
377371 => Int -> Stream m Int -> m ()
378372
373+filterAllOut,
374+ filterAllIn, takeAll, takeWhileTrue, takeWhileMTrue,
375+ dropAll, dropWhileTrue, dropWhileMTrue, dropWhileFalse,
376+ findIndices, elemIndices, insertBy, deleteBy
377+ :: MonadIO m
378+ => Int -> Int -> Stream m Int -> m ()
379+
379380{-# INLINE mapMaybeM #-}
380381{-# INLINE intersperse #-}
381−mapMaybeM, intersperse :: S.MonadAsync m => Int -> Stream m Int -> m ()
382+mapMaybeM :: S.MonadAsync m => Int -> Stream m Int -> m ()
383+intersperse :: S.MonadAsync m => Int -> Int -> Stream m Int -> m ()
382384
383385{-# INLINE mapM #-}
384386{-# INLINE map' #-}
@@ -431,22 +433,22 @@ mapMaybeM n = composeN n $ S.mapMaybeM
431433 (\x -> if Prelude.odd x then return Nothing else return $ Just x)
432434sequence t = transform . t . S.sequence
433435filterEven n = composeN n $ S.filter even
434−filterAllOut n = composeN n $ S.filter (> maxValue)
435−filterAllIn n = composeN n $ S.filter (<= maxValue)
436+filterAllOut value n = composeN n $ S.filter (> (value + 1))
437+filterAllIn value n = composeN n $ S.filter (<= (value + 1))
436438takeOne n = composeN n $ S.take 1
437−takeAll n = composeN n $ S.take maxValue
438−takeWhileTrue n = composeN n $ S.takeWhile (<= maxValue)
439−takeWhileMTrue n = composeN n $ S.takeWhileM (return . (<= maxValue))
439+takeAll value n = composeN n $ S.take (value + 1)
440+takeWhileTrue value n = composeN n $ S.takeWhile (<= (value + 1))
441+takeWhileMTrue value n = composeN n $ S.takeWhileM (return . (<= (value + 1)))
440442dropOne n = composeN n $ S.drop 1
441−dropAll n = composeN n $ S.drop maxValue
442−dropWhileTrue n = composeN n $ S.dropWhile (<= maxValue)
443−dropWhileMTrue n = composeN n $ S.dropWhileM (return . (<= maxValue))
444−dropWhileFalse n = composeN n $ S.dropWhile (> maxValue)
445−findIndices n = composeN n $ S.findIndices (== maxValue)
446−elemIndices n = composeN n $ S.elemIndices maxValue
447−intersperse n = composeN n $ S.intersperse maxValue
448−insertBy n = composeN n $ S.insertBy compare maxValue
449−deleteBy n = composeN n $ S.deleteBy (>=) maxValue
443+dropAll value n = composeN n $ S.drop (value + 1)
444+dropWhileTrue value n = composeN n $ S.dropWhile (<= (value + 1))
445+dropWhileMTrue value n = composeN n $ S.dropWhileM (return . (<= (value + 1)))
446+dropWhileFalse value n = composeN n $ S.dropWhile (> (value + 1))
447+findIndices value n = composeN n $ S.findIndices (== (value + 1))
448+elemIndices value n = composeN n $ S.elemIndices (value + 1)
449+intersperse value n = composeN n $ S.intersperse (value + 1)
450+insertBy value n = composeN n $ S.insertBy compare (value + 1)
451+deleteBy value n = composeN n $ S.deleteBy (>=) (value + 1)
450452reverse n = composeN n $ S.reverse
451453reverse' n = composeN n $ Internal.reverse'
452454foldrS n = composeN n $ Internal.foldrS S.cons S.nil
@@ -493,21 +495,25 @@ transformZipMapM t n = composeN' n $ t . Internal.transform
493495{-# INLINE filterScan #-}
494496{-# INLINE filterScanl1 #-}
495497{-# INLINE filterMap #-}
496−scanMap, dropMap, dropScan, takeDrop, takeScan, takeMap, filterDrop,
497− filterTake, filterScan, filterScanl1, filterMap
498+scanMap, dropMap, dropScan,
499+ filterScan, filterScanl1
498500 :: MonadIO m => Int -> Stream m Int -> m ()
499501
502+takeDrop, takeScan, takeMap, filterDrop,
503+ filterTake, filterMap
504+ :: MonadIO m => Int -> Int -> Stream m Int -> m ()
505+
500506scanMap n = composeN n $ S.map (subtract 1) . S.scanl' (+) 0
501507dropMap n = composeN n $ S.map (subtract 1) . S.drop 1
502508dropScan n = composeN n $ S.scanl' (+) 0 . S.drop 1
503−takeDrop n = composeN n $ S.drop 1 . S.take maxValue
504−takeScan n = composeN n $ S.scanl' (+) 0 . S.take maxValue
505−takeMap n = composeN n $ S.map (subtract 1) . S.take maxValue
506−filterDrop n = composeN n $ S.drop 1 . S.filter (<= maxValue)
507−filterTake n = composeN n $ S.take maxValue . S.filter (<= maxValue)
509+takeDrop value n = composeN n $ S.drop 1 . S.take (value + 1)
510+takeScan value n = composeN n $ S.scanl' (+) 0 . S.take (value + 1)
511+takeMap value n = composeN n $ S.map (subtract 1) . S.take (value + 1)
512+filterDrop value n = composeN n $ S.drop 1 . S.filter (<= (value + 1))
513+filterTake value n = composeN n $ S.take (value + 1) . S.filter (<= (value + 1))
508514filterScan n = composeN n $ S.scanl' (+) 0 . S.filter (<= maxBound)
509515filterScanl1 n = composeN n $ S.scanl1' (+) . S.filter (<= maxBound)
510−filterMap n = composeN n $ S.map (subtract 1) . S.filter (<= maxValue)
516+filterMap value n = composeN n $ S.map (subtract 1) . S.filter (<= (value + 1))
511517
512518-------------------------------------------------------------------------------
513519-- Scan and fold
@@ -549,11 +555,16 @@ iterateSource g i n = f i (sourceUnfoldrMN iterStreamLen n)
549555{-# INLINE iterateDropOne #-}
550556{-# INLINE iterateDropWhileFalse #-}
551557{-# INLINE iterateDropWhileTrue #-}
552−iterateMapM, iterateScan, iterateScanl1, iterateFilterEven, iterateTakeAll,
553− iterateDropOne, iterateDropWhileFalse, iterateDropWhileTrue
558+iterateMapM, iterateScan, iterateScanl1, iterateFilterEven,
559+ iterateDropOne
554560 :: S.MonadAsync m
555561 => Int -> Stream m Int
556562
563+iterateTakeAll,
564+ iterateDropWhileFalse, iterateDropWhileTrue
565+ :: S.MonadAsync m
566+ => Int -> Int -> Stream m Int
567+
557568-- this is quadratic
558569iterateScan = iterateSource (S.scanl' (+) 0) (maxIters `div` 10)
559570-- so is this
@@ -561,10 +572,10 @@ iterateScanl1 = iterateSource (S.scanl1' (+)) (maxIters `div` 10)
561572
562573iterateMapM = iterateSource (S.mapM return) maxIters
563574iterateFilterEven = iterateSource (S.filter even) maxIters
564−iterateTakeAll = iterateSource (S.take maxValue) maxIters
575+iterateTakeAll value = iterateSource (S.take (value + 1)) maxIters
565576iterateDropOne = iterateSource (S.drop 1) maxIters
566−iterateDropWhileFalse = iterateSource (S.dropWhile (> maxValue)) maxIters
567−iterateDropWhileTrue = iterateSource (S.dropWhile (<= maxValue)) maxIters
577+iterateDropWhileFalse value = iterateSource (S.dropWhile (> (value + 1))) maxIters
578+iterateDropWhileTrue value = iterateSource (S.dropWhile (<= (value + 1))) maxIters
568579
569580-------------------------------------------------------------------------------
570581-- Combining streams
@@ -616,14 +627,14 @@ inspect $ 'append2 `hasNoType` ''D.AppendState
616627-------------------------------------------------------------------------------
617628
618629{-# INLINE wSerial2 #-}
619−wSerial2 :: Int -> IO ()
620−wSerial2 n = S.drain $ S.wSerial
630+wSerial2 :: Int -> Int -> IO ()
631+wSerial2 value n = S.drain $ S.wSerial
621632 (sourceUnfoldrMN (value `div` 2) n)
622633 (sourceUnfoldrMN (value `div` 2) (n + 1))
623634
624635{-# INLINE interleave2 #-}
625−interleave2 :: Int -> IO ()
626−interleave2 n = S.drain $ Internal.interleave
636+interleave2 :: Int -> Int -> IO ()
637+interleave2 value n = S.drain $ Internal.interleave
627638 (sourceUnfoldrMN (value `div` 2) n)
628639 (sourceUnfoldrMN (value `div` 2) (n + 1))
629640
@@ -633,8 +644,8 @@ inspect $ 'interleave2 `hasNoType` ''D.InterleaveState
633644#endif
634645
635646{-# INLINE roundRobin2 #-}
636−roundRobin2 :: Int -> IO ()
637−roundRobin2 n = S.drain $ Internal.roundrobin
647+roundRobin2 :: Int -> Int -> IO ()
648+roundRobin2 value n = S.drain $ Internal.roundrobin
638649 (sourceUnfoldrMN (value `div` 2) n)
639650 (sourceUnfoldrMN (value `div` 2) (n + 1))
640651
@@ -730,8 +741,8 @@ eqBy' :: (Monad m, P.Eq a) => Stream m a -> m P.Bool
730741eqBy' src = S.eqBy (==) src src
731742
732743{-# INLINE eqBy #-}
733−eqBy :: Int -> IO Bool
734−eqBy n = eqBy' (source n)
744+eqBy :: Int -> Int -> IO Bool
745+eqBy value n = eqBy' (source value n)
735746
736747#ifdef INSPECTION
737748inspect $ hasNoTypeClasses 'eqBy
@@ -740,8 +751,8 @@ inspect $ 'eqBy `hasNoType` ''D.Step
740751
741752
742753{-# INLINE eqByPure #-}
743−eqByPure :: Int -> Identity Bool
744−eqByPure n = eqBy' (sourceUnfoldr n)
754+eqByPure :: Int -> Int -> Identity Bool
755+eqByPure value n = eqBy' (sourceUnfoldr value n)
745756
746757#ifdef INSPECTION
747758inspect $ hasNoTypeClasses 'eqByPure
@@ -753,8 +764,8 @@ cmpBy' :: (Monad m, P.Ord a) => Stream m a -> m P.Ordering
753764cmpBy' src = S.cmpBy P.compare src src
754765
755766{-# INLINE cmpBy #-}
756−cmpBy :: Int -> IO P.Ordering
757−cmpBy n = cmpBy' (source n)
767+cmpBy :: Int -> Int -> IO P.Ordering
768+cmpBy value n = cmpBy' (source value n)
758769
759770#ifdef INSPECTION
760771inspect $ hasNoTypeClasses 'cmpBy
@@ -762,8 +773,8 @@ inspect $ 'cmpBy `hasNoType` ''D.Step
762773#endif
763774
764775{-# INLINE cmpByPure #-}
765−cmpByPure :: Int -> Identity P.Ordering
766−cmpByPure n = cmpBy' (sourceUnfoldr n)
776+cmpByPure :: Int -> Int -> Identity P.Ordering
777+cmpByPure value n = cmpBy' (sourceUnfoldr value n)
767778
768779#ifdef INSPECTION
769780inspect $ hasNoTypeClasses 'cmpByPure
@@ -778,23 +789,23 @@ inspect $ 'cmpByPure `hasNoType` ''D.Step
778789
779790{-# INLINE sourceFoldMapWith #-}
780791sourceFoldMapWith :: (S.IsStream t, S.Semigroup (t m Int))
781− => Int -> t m Int
782−sourceFoldMapWith n = S.foldMapWith (S.<>) S.yield [n..n+value]
792+ => Int -> Int -> t m Int
793+sourceFoldMapWith value n = S.foldMapWith (S.<>) S.yield [n..n+value]
783794
784795{-# INLINE sourceFoldMapWithM #-}
785796sourceFoldMapWithM :: (S.IsStream t, Monad m, S.Semigroup (t m Int))
786− => Int -> t m Int
787−sourceFoldMapWithM n = S.foldMapWith (S.<>) (S.yieldM . return) [n..n+value]
797+ => Int -> Int -> t m Int
798+sourceFoldMapWithM value n = S.foldMapWith (S.<>) (S.yieldM . return) [n..n+value]
788799
789800{-# INLINE sourceFoldMapM #-}
790801sourceFoldMapM :: (S.IsStream t, Monad m, P.Monoid (t m Int))
791− => Int -> t m Int
792−sourceFoldMapM n = F.foldMap (S.yieldM . return) [n..n+value]
802+ => Int -> Int -> t m Int
803+sourceFoldMapM value n = F.foldMap (S.yieldM . return) [n..n+value]
793804
794805{-# INLINE sourceConcatMapId #-}
795806sourceConcatMapId :: (S.IsStream t, Monad m)
796− => Int -> t m Int
797−sourceConcatMapId n =
807+ => Int -> Int -> t m Int
808+sourceConcatMapId value n =
798809 S.concatMap P.id $ S.fromFoldable $ P.map (S.yieldM . return) [n..n+value]
799810
800811-- concatMap unfoldrM/unfoldrM
@@ -826,8 +837,8 @@ inspect $ hasNoTypeClasses 'concatMapPure
826837-- concatMap replicate/unfoldrM
827838
828839{-# INLINE concatMapRepl4xN #-}
829−concatMapRepl4xN :: Int -> IO ()
830−concatMapRepl4xN n = S.drain $ S.concatMap (S.replicate 4)
840+concatMapRepl4xN :: Int -> Int -> IO ()
841+concatMapRepl4xN value n = S.drain $ S.concatMap (S.replicate 4)
831842 (sourceUnfoldrMN (value `div` 4) n)
832843
833844#ifdef INSPECTION
@@ -877,8 +888,8 @@ inspect $ hasNoTypeClasses 'concatMapWithWSerial
877888-- concatUnfold replicate/unfoldrM
878889
879890{-# INLINE concatUnfoldRepl4xN #-}
880−concatUnfoldRepl4xN :: Int -> IO ()
881−concatUnfoldRepl4xN n =
891+concatUnfoldRepl4xN :: Int -> Int -> IO ()
892+concatUnfoldRepl4xN value n =
882893 S.drain $ S.concatUnfold
883894 (UF.replicateM 4)
884895 (sourceUnfoldrMN (value `div` 4) n)
@@ -889,8 +900,8 @@ inspect $ 'concatUnfoldRepl4xN `hasNoType` ''D.ConcatMapUState
889900#endif
890901
891902{-# INLINE concatUnfoldInterleaveRepl4xN #-}
892−concatUnfoldInterleaveRepl4xN :: Int -> IO ()
893−concatUnfoldInterleaveRepl4xN n =
903+concatUnfoldInterleaveRepl4xN :: Int -> Int -> IO ()
904+concatUnfoldInterleaveRepl4xN value n =
894905 S.drain $ Internal.concatUnfoldInterleave
895906 (UF.replicateM 4)
896907 (sourceUnfoldrMN (value `div` 4) n)
@@ -901,8 +912,8 @@ inspect $ hasNoTypeClasses 'concatUnfoldInterleaveRepl4xN
901912#endif
902913
903914{-# INLINE concatUnfoldRoundrobinRepl4xN #-}
904−concatUnfoldRoundrobinRepl4xN :: Int -> IO ()
905−concatUnfoldRoundrobinRepl4xN n =
915+concatUnfoldRoundrobinRepl4xN :: Int -> Int -> IO ()
916+concatUnfoldRoundrobinRepl4xN value n =
906917 S.drain $ Internal.concatUnfoldRoundrobin
907918 (UF.replicateM 4)
908919 (sourceUnfoldrMN (value `div` 4) n)
@@ -918,8 +929,8 @@ inspect $ hasNoTypeClasses 'concatUnfoldRoundrobinRepl4xN
918929
919930{-# INLINE sourceUnfoldrState #-}
920931sourceUnfoldrState :: (S.IsStream t, S.MonadAsync m)
921− => Int -> t (StateT Int m) Int
922−sourceUnfoldrState n = S.unfoldrM step n
932+ => Int -> Int -> t (StateT Int m) Int
933+sourceUnfoldrState value n = S.unfoldrM step n
923934 where
924935 step cnt =
925936 if cnt > n + value
@@ -930,13 +941,13 @@ sourceUnfoldrState n = S.unfoldrM step n
930941 return (Just (s, cnt + 1))
931942
932943{-# INLINE evalStateT #-}
933−evalStateT :: S.MonadAsync m => Int -> Stream m Int
934−evalStateT n = Internal.evalStateT 0 (sourceUnfoldrState n)
944+evalStateT :: S.MonadAsync m => Int -> Int -> Stream m Int
945+evalStateT value n = Internal.evalStateT 0 (sourceUnfoldrState value n)
935946
936947{-# INLINE withState #-}
937−withState :: S.MonadAsync m => Int -> Stream m Int
938−withState n =
939− Internal.evalStateT (0 :: Int) (Internal.liftInner (sourceUnfoldrM n))
948+withState :: S.MonadAsync m => Int -> Int -> Stream m Int
949+withState value n =
950+ Internal.evalStateT (0 :: Int) (Internal.liftInner (sourceUnfoldrM value n))
940951
941952-------------------------------------------------------------------------------
942953-- Concurrent application/fold
streamly.cabal+9−45
@@ -584,6 +584,15 @@ test-suite parallel-loops
584584-- Benchmarks
585585-------------------------------------------------------------------------------
586586
587+-- NOTE :
588+-- For linear, linear-async and linear-rate if you want to pass the number
589+-- of stream elements for benchmarking then you can pass it as the first
590+-- argument after `--`, as a gauge argument. If you don't give the argument,
591+-- the number of stream elements default to 100000.
592+-- Examples:
593+-- $ cabal run linear -- 1000000 [additional gauge options here...]
594+-- $ cabal run linear -- [additional gauge options here...]
595+
587596benchmark linear
588597 import: bench-options
589598 type: exitcode-stdio-1.0
@@ -603,26 +612,6 @@ benchmark linear
603612 build-depends: template-haskell >= 2.14 && < 2.16
604613 , inspection-testing >= 0.4 && < 0.5
605614
606−benchmark linear-long
607− import: bench-options-threaded
608− type: exitcode-stdio-1.0
609− cpp-options: -DLONG_BENCHMARKS
610− hs-source-dirs: benchmark
611− main-is: Linear.hs
612− other-modules: Streamly.Benchmark.Prelude
613− build-depends:
614− streamly
615− , base >= 4.8 && < 5
616− , deepseq >= 1.4.1 && < 1.5
617− , random >= 1.0 && < 2.0
618− , gauge >= 0.2.4 && < 0.3
619− if impl(ghc < 8.0)
620− build-depends:
621− transformers >= 0.4 && < 0.6
622− if flag(inspection)
623− build-depends: template-haskell >= 2.14 && < 2.16
624− , inspection-testing >= 0.4 && < 0.5
625−
626615benchmark nested
627616 import: bench-options
628617 type: exitcode-stdio-1.0
@@ -729,7 +718,6 @@ benchmark fileio
729718
730719benchmark linear-async
731720 import: bench-options-threaded
732− cpp-options: -DLINEAR_ASYNC
733721 type: exitcode-stdio-1.0
734722 hs-source-dirs: benchmark
735723 main-is: LinearAsync.hs
@@ -747,30 +735,6 @@ benchmark linear-async
747735 build-depends: template-haskell >= 2.14 && < 2.16
748736 , inspection-testing >= 0.4 && < 0.5
749737
750−benchmark linear-async-long
751− import: bench-options-threaded
752− cpp-options: -DLONG_BENCHMARKS
753− type: exitcode-stdio-1.0
754− hs-source-dirs: benchmark
755− main-is: LinearAsync.hs
756− other-modules: Streamly.Benchmark.Prelude
757− if flag(dev)
758− buildable: True
759− build-depends:
760− streamly
761− , base >= 4.8 && < 5
762− , deepseq >= 1.4.1 && < 1.5
763− , random >= 1.0 && < 2.0
764− , gauge >= 0.2.4 && < 0.3
765− if impl(ghc < 8.0)
766− build-depends:
767− transformers >= 0.4 && < 0.6
768− if flag(inspection)
769− build-depends: template-haskell >= 2.14 && < 2.16
770− , inspection-testing >= 0.4 && < 0.5
771− else
772− buildable: False
773−
774738benchmark nested-concurrent
775739 import: bench-options-threaded
776740 type: exitcode-stdio-1.0