on master help sign in
Move Prelude.Serial benchmarks to Data.Stream
8fbc085Ranjeet Kumar Ranjan
.github/workflows/regression-check.yml+1−1
@@ -25,6 +25,7 @@ jobs:
25 Data.Parser.ParserD
25 Data.Parser.ParserD
26 Data.Parser.ParserK
26 Data.Parser.ParserK
27 Data.SmallArray
27 Data.SmallArray
28+ Data.Stream
28 Data.Stream.StreamD
29 Data.Stream.StreamD
29 Data.Stream.StreamDK
30 Data.Stream.StreamDK
30 Data.Stream.StreamK:6
31 Data.Stream.StreamK:6
@@ -33,7 +34,6 @@ jobs:
33 Prelude.Ahead
34 Prelude.Ahead
34 Prelude.Async:12
35 Prelude.Async:12
35 Prelude.Parallel
36 Prelude.Parallel
36− Prelude.Serial
37 Prelude.WAsync:6
37 Prelude.WAsync:6
38 Prelude.WSerial
38 Prelude.WSerial
39 Prelude.ZipAsync
39 Prelude.ZipAsync
.hlint.yaml+7−6
@@ -26,12 +26,13 @@
26- ignore: {name: "Use fmap"}
26- ignore: {name: "Use fmap"}
27
27
28# Warnings ignored in specific places
28# Warnings ignored in specific places
29−- ignore: {name: "Use ++", within: Serial.Transformation}
29+- ignore: {name: "Use ++", within: Stream.Transformation}
30−- ignore: {name: "Use mapM", within: Serial.Transformation}
30+- ignore: {name: "Use mapM", within: Stream.Transformation}
31−- ignore: {name: "Use traverse", within: Serial.Transformation}
31+- ignore: {name: "Use traverse", within: Stream.Transformation}
32−
33−- ignore: {name: "Redundant <*", within: Serial.NestedStream}
32+- ignore: {name: "Redundant <*", within: Stream.NestedStream}
34−- ignore: {name: "Use ++", within: Serial.NestedStream}
33+- ignore: {name: "Use ++", within: Stream.NestedStream}
34+- ignore: {name: "Use ++", within: Stream.Split}
35+- ignore: {name: "Redundant bracket", within: Stream.Split}
35- ignore: {name: "Use isDigit", within: Streamly.Internal.Unicode.Char.Parser}
36- ignore: {name: "Use isDigit", within: Streamly.Internal.Unicode.Char.Parser}
36
37
37# Specify additional command line arguments
38# Specify additional command line arguments
benchmark/Streamly/Benchmark/Prelude/Serial.hs → benchmark/Streamly/Benchmark/Data/Stream.hsrenamed+20−14
@@ -1,5 +1,5 @@
1-- |
1-- |
2−-- Module : Serial
2+-- Module : Data.Stream
3-- Copyright : (c) 2018 Composewell Technologies
3-- Copyright : (c) 2018 Composewell Technologies
4-- License : BSD-3-Clause
4-- License : BSD-3-Clause
5-- Maintainer : streamly@composewell.com
5-- Maintainer : streamly@composewell.com
@@ -13,19 +13,22 @@ module Main (main) where
13
13
14import Streamly.Benchmark.Common.Handle (mkHandleBenchEnv)
14import Streamly.Benchmark.Common.Handle (mkHandleBenchEnv)
15
15
16−import qualified Serial.Elimination as Elimination
16+import qualified Stream.Eliminate as Elimination
17−import qualified Serial.Exceptions as Exceptions
17+import qualified Stream.Exceptions as Exceptions
18−import qualified Serial.Generation as Generation
18+import qualified Stream.Generate as Generation
19−import qualified Serial.NestedStream as NestedStream
19+import qualified Stream.Lift as Lift
20−import qualified Serial.Split as Split
20+import qualified Stream.Reduce as Reduction
21−import qualified Serial.Transformation as Transformation
21+import qualified Stream.Transformation as Transformation
22+#ifdef USE_PRELUDE
22−import qualified Serial.NestedFold as NestedFold
23+import qualified Stream.NestedFold as NestedFold
23−import qualified Serial.Lift as Lift
24+import qualified Stream.NestedStream as NestedStream
25+import qualified Stream.Split as Split
26+#endif
24
27
25import Streamly.Benchmark.Common
28import Streamly.Benchmark.Common
26
29
27moduleName :: String
30moduleName :: String
28−moduleName = "Prelude.Serial"
31+moduleName = "Data.Stream"
29
32
30-------------------------------------------------------------------------------
33-------------------------------------------------------------------------------
31-- Main
34-- Main
@@ -42,12 +45,15 @@ main = do
42 where
45 where
43
46
44 allBenchmarks env size = Prelude.concat
47 allBenchmarks env size = Prelude.concat
45− [ Generation.benchmarks moduleName size
46− , Elimination.benchmarks moduleName size
48+ [ Elimination.benchmarks moduleName size
47 , Exceptions.benchmarks moduleName env size
49 , Exceptions.benchmarks moduleName env size
50+ , Generation.benchmarks moduleName size
51+ , Lift.benchmarks moduleName size
48− , Split.benchmarks moduleName env
52+ , Reduction.benchmarks moduleName size
49 , Transformation.benchmarks moduleName size
53 , Transformation.benchmarks moduleName size
54+#ifdef USE_PRELUDE
50 , NestedFold.benchmarks moduleName size
55 , NestedFold.benchmarks moduleName size
51− , Lift.benchmarks moduleName size
52 , NestedStream.benchmarks moduleName size
56 , NestedStream.benchmarks moduleName size
57+ , Split.benchmarks moduleName env
58+#endif
53 ]
59 ]
benchmark/Streamly/Benchmark/Data/Stream/Common.hsnew file+70
@@ -0,0 +1,70 @@
1+-- |
2+-- Module : Stream.Common
3+-- Copyright : (c) 2018 Composewell Technologies
4+-- License : BSD-3-Clause
5+-- Maintainer : streamly@composewell.com
6+
7+module Stream.Common
8+ ( sourceUnfoldr
9+ , sourceUnfoldrM
10+ , sourceUnfoldrAction
11+ , benchIOSink
12+ , benchIOSrc
13+ )
14+where
15+
16+import Streamly.Internal.Data.Stream (Stream, unfold)
17+import qualified Streamly.Internal.Data.Fold as Fold
18+import qualified Streamly.Internal.Data.Stream as Stream
19+import qualified Streamly.Internal.Data.Unfold as UF
20+import Control.DeepSeq (NFData)
21+import Gauge
22+import Prelude hiding (mapM)
23+import System.Random (randomRIO)
24+
25+{-# INLINE toNull #-}
26+toNull :: Monad m => Stream m a -> m ()
27+toNull = Stream.fold Fold.drain
28+
29+{-# INLINE sourceUnfoldrM #-}
30+sourceUnfoldrM :: Monad m => Int -> Int -> Stream m Int
31+sourceUnfoldrM count start = unfold (UF.unfoldrM step) start
32+ where
33+ step cnt =
34+ if cnt > start + count
35+ then return Nothing
36+ else return (Just (cnt, cnt + 1))
37+
38+{-# INLINE sourceUnfoldr #-}
39+sourceUnfoldr :: Monad m => Int -> Int -> Stream m Int
40+sourceUnfoldr count start = unfold (UF.unfoldr step) start
41+ where
42+ step cnt =
43+ if cnt > start + count
44+ then Nothing
45+ else Just (cnt, cnt + 1)
46+
47+{-# INLINE sourceUnfoldrAction #-}
48+sourceUnfoldrAction :: (Monad m1, Monad m) => Int -> Int -> Stream m (m1 Int)
49+sourceUnfoldrAction value n = unfold (UF.unfoldr step) n
50+ where
51+ step cnt =
52+ if cnt > n + value
53+ then Nothing
54+ else Just (return cnt, cnt + 1)
55+
56+{-# INLINE benchIOSink #-}
57+benchIOSink
58+ :: (NFData b)
59+ => Int -> String -> (Stream IO Int -> IO b) -> Benchmark
60+benchIOSink value name f =
61+ bench name $ nfIO $ randomRIO (1,1) >>= f . sourceUnfoldrM value
62+
63+-- | Takes a source, and uses it with a default drain/fold method.
64+{-# INLINE benchIOSrc #-}
65+benchIOSrc
66+ :: String
67+ -> (Int -> Stream IO a)
68+ -> Benchmark
69+benchIOSrc name f =
70+ bench name $ nfIO $ randomRIO (1,1) >>= toNull . f
benchmark/Streamly/Benchmark/Prelude/Serial/Elimination.hs → benchmark/Streamly/Benchmark/Data/Stream/Eliminate.hsrenamed+88−59
@@ -1,5 +1,5 @@
1-- |
1-- |
2−-- Module : Serial.Elimination
2+-- Module : Stream.Eliminate
3-- Copyright : (c) 2018 Composewell Technologies
3-- Copyright : (c) 2018 Composewell Technologies
4-- License : BSD-3-Clause
4-- License : BSD-3-Clause
5-- Maintainer : streamly@composewell.com
5-- Maintainer : streamly@composewell.com
@@ -18,7 +18,7 @@
18{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
18{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
19#endif
19#endif
20
20
21−module Serial.Elimination (benchmarks) where
21+module Stream.Eliminate (benchmarks) where
22
22
23import Control.DeepSeq (NFData(..))
23import Control.DeepSeq (NFData(..))
24import Data.Functor.Identity (Identity, runIdentity)
24import Data.Functor.Identity (Identity, runIdentity)
@@ -33,22 +33,39 @@ import Test.Inspection
33
33
34import qualified Streamly.Internal.Data.Stream.StreamD as D
34import qualified Streamly.Internal.Data.Stream.StreamD as D
35#endif
35#endif
36−
36+import qualified Streamly.Internal.Data.Fold as Fold
37+#ifdef USE_PRELUDE
37import qualified Streamly.Prelude as S
38import qualified Streamly.Prelude as S
39+import qualified Streamly.Internal.Data.Stream.IsStream as S
38import qualified Streamly.Internal.Data.Stream.IsStream as Internal
40import qualified Streamly.Internal.Data.Stream.IsStream as Internal
41+#else
42+import qualified Streamly.Internal.Data.Stream as S
43+#endif
39
44
40import Gauge
45import Gauge
41−import Streamly.Prelude (SerialT, IsStream, fromSerial)
46+import Streamly.Internal.Data.Stream.Serial (SerialT)
42−import Streamly.Benchmark.Common
47+#ifdef USE_PRELUDE
48+import Streamly.Prelude (fromSerial)
43import Streamly.Benchmark.Prelude
49import Streamly.Benchmark.Prelude
50+#else
51+import Stream.Common
52+ ( sourceUnfoldr
53+ , sourceUnfoldrM
54+ , sourceUnfoldrAction
55+ , benchIOSink
56+ )
57+#endif
58+import Streamly.Benchmark.Common
59+
44import Prelude hiding (length, sum, or, and, any, all, notElem, elem, (!!),
60import Prelude hiding (length, sum, or, and, any, all, notElem, elem, (!!),
45 lookup, repeat, minimum, maximum, product, last, mapM_, init)
61 lookup, repeat, minimum, maximum, product, last, mapM_, init)
46import qualified Prelude
62import qualified Prelude
47
63
64+#ifdef USE_PRELUDE
48{-# INLINE repeat #-}
65{-# INLINE repeat #-}
49repeat :: (Monad m, S.IsStream t) => Int -> Int -> t m Int
66repeat :: (Monad m, S.IsStream t) => Int -> Int -> t m Int
50repeat count = S.take count . S.repeat
67repeat count = S.take count . S.repeat
51−
68+#endif
52-------------------------------------------------------------------------------
69-------------------------------------------------------------------------------
53-- Elimination
70-- Elimination
54-------------------------------------------------------------------------------
71-------------------------------------------------------------------------------
@@ -60,76 +77,76 @@ repeat count = S.take count . S.repeat
60{-# INLINE foldableFoldl' #-}
77{-# INLINE foldableFoldl' #-}
61foldableFoldl' :: Int -> Int -> Int
78foldableFoldl' :: Int -> Int -> Int
62foldableFoldl' value n =
79foldableFoldl' value n =
63− F.foldl' (+) 0 (sourceUnfoldr value n :: S.SerialT Identity Int)
80+ F.foldl' (+) 0 (sourceUnfoldr value n :: SerialT Identity Int)
64
81
65{-# INLINE foldableFoldrElem #-}
82{-# INLINE foldableFoldrElem #-}
66foldableFoldrElem :: Int -> Int -> Bool
83foldableFoldrElem :: Int -> Int -> Bool
67foldableFoldrElem value n =
84foldableFoldrElem value n =
68 F.foldr (\x xs -> x == value || xs)
85 F.foldr (\x xs -> x == value || xs)
69 False
86 False
70− (sourceUnfoldr value n :: S.SerialT Identity Int)
87+ (sourceUnfoldr value n :: SerialT Identity Int)
71
88
72{-# INLINE foldableSum #-}
89{-# INLINE foldableSum #-}
73foldableSum :: Int -> Int -> Int
90foldableSum :: Int -> Int -> Int
74foldableSum value n =
91foldableSum value n =
75− Prelude.sum (sourceUnfoldr value n :: S.SerialT Identity Int)
92+ Prelude.sum (sourceUnfoldr value n :: SerialT Identity Int)
76
93
77{-# INLINE foldableProduct #-}
94{-# INLINE foldableProduct #-}
78foldableProduct :: Int -> Int -> Int
95foldableProduct :: Int -> Int -> Int
79foldableProduct value n =
96foldableProduct value n =
80− Prelude.product (sourceUnfoldr value n :: S.SerialT Identity Int)
97+ Prelude.product (sourceUnfoldr value n :: SerialT Identity Int)
81
98
82{-# INLINE _foldableNull #-}
99{-# INLINE _foldableNull #-}
83_foldableNull :: Int -> Int -> Bool
100_foldableNull :: Int -> Int -> Bool
84_foldableNull value n =
101_foldableNull value n =
85− Prelude.null (sourceUnfoldr value n :: S.SerialT Identity Int)
102+ Prelude.null (sourceUnfoldr value n :: SerialT Identity Int)
86
103
87{-# INLINE foldableElem #-}
104{-# INLINE foldableElem #-}
88foldableElem :: Int -> Int -> Bool
105foldableElem :: Int -> Int -> Bool
89foldableElem value n =
106foldableElem value n =
90− value `Prelude.elem` (sourceUnfoldr value n :: S.SerialT Identity Int)
107+ value `Prelude.elem` (sourceUnfoldr value n :: SerialT Identity Int)
91
108
92{-# INLINE foldableNotElem #-}
109{-# INLINE foldableNotElem #-}
93foldableNotElem :: Int -> Int -> Bool
110foldableNotElem :: Int -> Int -> Bool
94foldableNotElem value n =
111foldableNotElem value n =
95− value `Prelude.notElem` (sourceUnfoldr value n :: S.SerialT Identity Int)
112+ value `Prelude.notElem` (sourceUnfoldr value n :: SerialT Identity Int)
96
113
97{-# INLINE foldableFind #-}
114{-# INLINE foldableFind #-}
98foldableFind :: Int -> Int -> Maybe Int
115foldableFind :: Int -> Int -> Maybe Int
99foldableFind value n =
116foldableFind value n =
100− F.find (== (value + 1)) (sourceUnfoldr value n :: S.SerialT Identity Int)
117+ F.find (== (value + 1)) (sourceUnfoldr value n :: SerialT Identity Int)
101
118
102{-# INLINE foldableAll #-}
119{-# INLINE foldableAll #-}
103foldableAll :: Int -> Int -> Bool
120foldableAll :: Int -> Int -> Bool
104foldableAll value n =
121foldableAll value n =
105− Prelude.all (<= (value + 1)) (sourceUnfoldr value n :: S.SerialT Identity Int)
122+ Prelude.all (<= (value + 1)) (sourceUnfoldr value n :: SerialT Identity Int)
106
123
107{-# INLINE foldableAny #-}
124{-# INLINE foldableAny #-}
108foldableAny :: Int -> Int -> Bool
125foldableAny :: Int -> Int -> Bool
109foldableAny value n =
126foldableAny value n =
110− Prelude.any (> (value + 1)) (sourceUnfoldr value n :: S.SerialT Identity Int)
127+ Prelude.any (> (value + 1)) (sourceUnfoldr value n :: SerialT Identity Int)
111
128
112{-# INLINE foldableAnd #-}
129{-# INLINE foldableAnd #-}
113foldableAnd :: Int -> Int -> Bool
130foldableAnd :: Int -> Int -> Bool
114foldableAnd value n =
131foldableAnd value n =
115− Prelude.and $ S.map
132+ Prelude.and $ fmap
116− (<= (value + 1)) (sourceUnfoldr value n :: S.SerialT Identity Int)
133+ (<= (value + 1)) (sourceUnfoldr value n :: SerialT Identity Int)
117
134
118{-# INLINE foldableOr #-}
135{-# INLINE foldableOr #-}
119foldableOr :: Int -> Int -> Bool
136foldableOr :: Int -> Int -> Bool
120foldableOr value n =
137foldableOr value n =
121− Prelude.or $ S.map
138+ Prelude.or $ fmap
122− (> (value + 1)) (sourceUnfoldr value n :: S.SerialT Identity Int)
139+ (> (value + 1)) (sourceUnfoldr value n :: SerialT Identity Int)
123
140
124{-# INLINE foldableLength #-}
141{-# INLINE foldableLength #-}
125foldableLength :: Int -> Int -> Int
142foldableLength :: Int -> Int -> Int
126foldableLength value n =
143foldableLength value n =
127− Prelude.length (sourceUnfoldr value n :: S.SerialT Identity Int)
144+ Prelude.length (sourceUnfoldr value n :: SerialT Identity Int)
128
145
129{-# INLINE foldableMin #-}
146{-# INLINE foldableMin #-}
130foldableMin :: Int -> Int -> Int
147foldableMin :: Int -> Int -> Int
131foldableMin value n =
148foldableMin value n =
132− Prelude.minimum (sourceUnfoldr value n :: S.SerialT Identity Int)
149+ Prelude.minimum (sourceUnfoldr value n :: SerialT Identity Int)
133
150
134{-# INLINE ordInstanceMin #-}
151{-# INLINE ordInstanceMin #-}
135ordInstanceMin :: SerialT Identity Int -> SerialT Identity Int
152ordInstanceMin :: SerialT Identity Int -> SerialT Identity Int
@@ -138,12 +155,12 @@ ordInstanceMin src = min src src
138{-# INLINE foldableMax #-}
155{-# INLINE foldableMax #-}
139foldableMax :: Int -> Int -> Int
156foldableMax :: Int -> Int -> Int
140foldableMax value n =
157foldableMax value n =
141− Prelude.maximum (sourceUnfoldr value n :: S.SerialT Identity Int)
158+ Prelude.maximum (sourceUnfoldr value n :: SerialT Identity Int)
142
159
143{-# INLINE foldableMinBy #-}
160{-# INLINE foldableMinBy #-}
144foldableMinBy :: Int -> Int -> Int
161foldableMinBy :: Int -> Int -> Int
145foldableMinBy value n =
162foldableMinBy value n =
146− F.minimumBy compare (sourceUnfoldr value n :: S.SerialT Identity Int)
163+ F.minimumBy compare (sourceUnfoldr value n :: SerialT Identity Int)
147
164
148{-# INLINE foldableListMinBy #-}
165{-# INLINE foldableListMinBy #-}
149foldableListMinBy :: Int -> Int -> Int
166foldableListMinBy :: Int -> Int -> Int
@@ -152,27 +169,27 @@ foldableListMinBy value n = F.minimumBy compare [1..value+n]
152{-# INLINE foldableMaxBy #-}
169{-# INLINE foldableMaxBy #-}
153foldableMaxBy :: Int -> Int -> Int
170foldableMaxBy :: Int -> Int -> Int
154foldableMaxBy value n =
171foldableMaxBy value n =
155− F.maximumBy compare (sourceUnfoldr value n :: S.SerialT Identity Int)
172+ F.maximumBy compare (sourceUnfoldr value n :: SerialT Identity Int)
156
173
157{-# INLINE foldableToList #-}
174{-# INLINE foldableToList #-}
158foldableToList :: Int -> Int -> [Int]
175foldableToList :: Int -> Int -> [Int]
159foldableToList value n =
176foldableToList value n =
160− F.toList (sourceUnfoldr value n :: S.SerialT Identity Int)
177+ F.toList (sourceUnfoldr value n :: SerialT Identity Int)
161
178
162{-# INLINE foldableMapM_ #-}
179{-# INLINE foldableMapM_ #-}
163foldableMapM_ :: Monad m => Int -> Int -> m ()
180foldableMapM_ :: Monad m => Int -> Int -> m ()
164foldableMapM_ value n =
181foldableMapM_ value n =
165− F.mapM_ (\_ -> return ()) (sourceUnfoldr value n :: S.SerialT Identity Int)
182+ F.mapM_ (\_ -> return ()) (sourceUnfoldr value n :: SerialT Identity Int)
166
183
167{-# INLINE foldableSequence_ #-}
184{-# INLINE foldableSequence_ #-}
168foldableSequence_ :: Int -> Int -> IO ()
185foldableSequence_ :: Int -> Int -> IO ()
169foldableSequence_ value n =
186foldableSequence_ value n =
170− F.sequence_ (sourceUnfoldrAction value n :: S.SerialT Identity (IO Int))
187+ F.sequence_ (sourceUnfoldrAction value n :: SerialT Identity (IO Int))
171
188
172{-# INLINE _foldableMsum #-}
189{-# INLINE _foldableMsum #-}
173_foldableMsum :: Int -> Int -> IO Int
190_foldableMsum :: Int -> Int -> IO Int
174_foldableMsum value n =
191_foldableMsum value n =
175− F.msum (sourceUnfoldrAction value n :: S.SerialT Identity (IO Int))
192+ F.msum (sourceUnfoldrAction value n :: SerialT Identity (IO Int))
176
193
177{-# INLINE showInstance #-}
194{-# INLINE showInstance #-}
178showInstance :: SerialT Identity Int -> String
195showInstance :: SerialT Identity Int -> String
@@ -240,8 +257,8 @@ benchPureSink value name = benchPure name (sourceUnfoldr value)
240
257
241{-# INLINE benchHoistSink #-}
258{-# INLINE benchHoistSink #-}
242benchHoistSink
259benchHoistSink
243− :: (IsStream t, NFData b)
260+ :: (NFData b)
244− => Int -> String -> (t Identity Int -> IO b) -> Benchmark
261+ => Int -> String -> (SerialT Identity Int -> IO b) -> Benchmark
245benchHoistSink value name f =
262benchHoistSink value name f =
246 bench name $ nfIO $ randomRIO (1,1) >>= f . sourceUnfoldr value
263 bench name $ nfIO $ randomRIO (1,1) >>= f . sourceUnfoldr value
247
264
@@ -249,8 +266,8 @@ benchHoistSink value name f =
249-- we can't use it as it requires MonadAsync constraint.
266-- we can't use it as it requires MonadAsync constraint.
250{-# INLINE benchIdentitySink #-}
267{-# INLINE benchIdentitySink #-}
251benchIdentitySink
268benchIdentitySink
252− :: (IsStream t, NFData b)
269+ :: (NFData b)
253− => Int -> String -> (t Identity Int -> Identity b) -> Benchmark
270+ => Int -> String -> (SerialT Identity Int -> Identity b) -> Benchmark
254benchIdentitySink value name f = bench name $ nf (f . sourceUnfoldr value) 1
271benchIdentitySink value name f = bench name $ nf (f . sourceUnfoldr value) 1
255
272
256-------------------------------------------------------------------------------
273-------------------------------------------------------------------------------
@@ -264,7 +281,7 @@ uncons s = do
264 case r of
281 case r of
265 Nothing -> return ()
282 Nothing -> return ()
266 Just (_, t) -> uncons t
283 Just (_, t) -> uncons t
267−
284+#ifdef USE_PRELUDE
268{-# INLINE init #-}
285{-# INLINE init #-}
269init :: Monad m => SerialT m a -> m ()
286init :: Monad m => SerialT m a -> m ()
270init s = S.init s >>= Prelude.mapM_ S.drain
287init s = S.init s >>= Prelude.mapM_ S.drain
@@ -272,6 +289,7 @@ init s = S.init s >>= Prelude.mapM_ S.drain
272{-# INLINE mapM_ #-}
289{-# INLINE mapM_ #-}
273mapM_ :: Monad m => SerialT m Int -> m ()
290mapM_ :: Monad m => SerialT m Int -> m ()
274mapM_ = S.mapM_ (\_ -> return ())
291mapM_ = S.mapM_ (\_ -> return ())
292+#endif
275
293
276{-# INLINE foldrMElem #-}
294{-# INLINE foldrMElem #-}
277foldrMElem :: Monad m => Int -> SerialT m Int -> m Bool
295foldrMElem :: Monad m => Int -> SerialT m Int -> m Bool
@@ -290,7 +308,7 @@ foldrToStream = S.foldr S.cons S.nil
290{-# INLINE foldrMBuild #-}
308{-# INLINE foldrMBuild #-}
291foldrMBuild :: Monad m => SerialT m Int -> m [Int]
309foldrMBuild :: Monad m => SerialT m Int -> m [Int]
292foldrMBuild = S.foldrM (\x xs -> (x :) <$> xs) (return [])
310foldrMBuild = S.foldrM (\x xs -> (x :) <$> xs) (return [])
293−
311+#ifdef USE_PRELUDE
294{-# INLINE foldl'Reduce #-}
312{-# INLINE foldl'Reduce #-}
295foldl'Reduce :: Monad m => SerialT m Int -> m Int
313foldl'Reduce :: Monad m => SerialT m Int -> m Int
296foldl'Reduce = S.foldl' (+) 0
314foldl'Reduce = S.foldl' (+) 0
@@ -398,40 +416,47 @@ drainWhile = S.drainWhile (const True)
398{-# INLINE lookup #-}
416{-# INLINE lookup #-}
399lookup :: Monad m => Int -> SerialT m Int -> m (Maybe Int)
417lookup :: Monad m => Int -> SerialT m Int -> m (Maybe Int)
400lookup val = S.lookup val . S.map (\x -> (x, x))
418lookup val = S.lookup val . S.map (\x -> (x, x))
401−
419+#endif
402o_1_space_elimination_folds :: Int -> [Benchmark]
420o_1_space_elimination_folds :: Int -> [Benchmark]
403o_1_space_elimination_folds value =
421o_1_space_elimination_folds value =
404 [ bgroup "elimination"
422 [ bgroup "elimination"
405 -- Basic folds
423 -- Basic folds
424+ [
425+#ifdef USE_PRELUDE
406− [ bgroup "reduce"
426+ bgroup "reduce"
407 [ bgroup
427 [ bgroup
408 "IO"
428 "IO"
409 [ benchIOSink value "foldl'" foldl'Reduce
429 [ benchIOSink value "foldl'" foldl'Reduce
410 , benchIOSink value "foldl1'" foldl1'Reduce
430 , benchIOSink value "foldl1'" foldl1'Reduce
411 , benchIOSink value "foldlM'" foldlM'Reduce
431 , benchIOSink value "foldlM'" foldlM'Reduce
412 ]
432 ]
433+
413 , bgroup
434 , bgroup
414 "Identity"
435 "Identity"
415 [ benchIdentitySink value "foldl'" foldl'Reduce
436 [ benchIdentitySink value "foldl'" foldl'Reduce
416 , benchIdentitySink value "foldl1'" foldl1'Reduce
437 , benchIdentitySink value "foldl1'" foldl1'Reduce
417 , benchIdentitySink value "foldlM'" foldlM'Reduce
438 , benchIdentitySink value "foldlM'" foldlM'Reduce
418 ]
439 ]
419− ]
440+ ] ,
441+#endif
420− , bgroup "build"
442+ bgroup "build"
421 [ bgroup "IO"
443 [ bgroup "IO"
422 [ benchIOSink value "foldrMElem" (foldrMElem value)
444 [ benchIOSink value "foldrMElem" (foldrMElem value)
423 ]
445 ]
424 , bgroup "Identity"
446 , bgroup "Identity"
425 [ benchIdentitySink value "foldrMElem" (foldrMElem value)
447 [ benchIdentitySink value "foldrMElem" (foldrMElem value)
426− , benchIdentitySink value "foldrToStreamLength"
427− (S.length . runIdentity . foldrToStream)
428 , benchPureSink value "foldrMToListLength"
448 , benchPureSink value "foldrMToListLength"
429 (Prelude.length . runIdentity . foldrMBuild)
449 (Prelude.length . runIdentity . foldrMBuild)
450+ , benchIdentitySink value "foldrToStreamLength"
451+ (S.fold Fold.length . runIdentity . foldrToStream)
430 ]
452 ]
431 ]
453 ]
432
454
433 -- deconstruction
455 -- deconstruction
434 , benchIOSink value "uncons" uncons
456 , benchIOSink value "uncons" uncons
457+ , benchHoistSink value "length . generally"
458+ (S.fold Fold.length . S.generally)
459+#ifdef USE_PRELUDE
435 , benchIOSink value "init" init
460 , benchIOSink value "init" init
436
461
437 -- draining
462 -- draining
@@ -442,19 +467,18 @@ o_1_space_elimination_folds value =
442 , benchIOSink value "mapM_" mapM_
467 , benchIOSink value "mapM_" mapM_
443
468
444 -- this is too fast, causes all benchmarks reported in ns
469 -- this is too fast, causes all benchmarks reported in ns
445− -- , benchIOSink value "head" head
470+ --, benchIOSink value "head" head
446 , benchIOSink value "last" last
471 , benchIOSink value "last" last
447 , benchIOSink value "length" length
472 , benchIOSink value "length" length
448− , benchHoistSink value "length . generally"
449− (length . Internal.generally)
450 , benchIOSink value "sum" sum
473 , benchIOSink value "sum" sum
451 , benchIOSink value "product" product
474 , benchIOSink value "product" product
452 , benchIOSink value "maximumBy" maximumBy
475 , benchIOSink value "maximumBy" maximumBy
453 , benchIOSink value "maximum" maximum
476 , benchIOSink value "maximum" maximum
454 , benchIOSink value "minimumBy" minimumBy
477 , benchIOSink value "minimumBy" minimumBy
455 , benchIOSink value "minimum" minimum
478 , benchIOSink value "minimum" minimum
456−
479+#ifdef USE_PRELUDE
457 , bench "the" $ nfIO $ randomRIO (1,1) >>= the . repeat value
480 , bench "the" $ nfIO $ randomRIO (1,1) >>= the . repeat value
481+#endif
458 , benchIOSink value "find" (find value)
482 , benchIOSink value "find" (find value)
459 , benchIOSink value "findM" (findM value)
483 , benchIOSink value "findM" (findM value)
460 -- , benchIOSink value "lookupFirst" (lookup 1)
484 -- , benchIOSink value "lookupFirst" (lookup 1)
@@ -463,13 +487,14 @@ o_1_space_elimination_folds value =
463 , benchIOSink value "findIndex" (findIndex value)
487 , benchIOSink value "findIndex" (findIndex value)
464 , benchIOSink value "elemIndex" (elemIndex value)
488 , benchIOSink value "elemIndex" (elemIndex value)
465 -- this is too fast, causes all benchmarks reported in ns
489 -- this is too fast, causes all benchmarks reported in ns
466− -- , benchIOSink value "null" S.null
490+ -- , benchIOSink value "null" S.null
467 , benchIOSink value "elem" (elem value)
491 , benchIOSink value "elem" (elem value)
468 , benchIOSink value "notElem" (notElem value)
492 , benchIOSink value "notElem" (notElem value)
469 , benchIOSink value "all" (all value)
493 , benchIOSink value "all" (all value)
470 , benchIOSink value "any" (any value)
494 , benchIOSink value "any" (any value)
471 , benchIOSink value "and" (and value)
495 , benchIOSink value "and" (and value)
472 , benchIOSink value "or" (or value)
496 , benchIOSink value "or" (or value)
497+#endif
473
498
474 -- length is used to check for foldr/build fusion
499 -- length is used to check for foldr/build fusion
475 , benchPureSink value "length . IsList.toList" (Prelude.length . GHC.toList)
500 , benchPureSink value "length . IsList.toList" (Prelude.length . GHC.toList)
@@ -479,7 +504,7 @@ o_1_space_elimination_folds value =
479-------------------------------------------------------------------------------
504-------------------------------------------------------------------------------
480-- Buffered Transformations by fold
505-- Buffered Transformations by fold
481-------------------------------------------------------------------------------
506-------------------------------------------------------------------------------
482−
507+#ifdef USE_PRELUDE
483{-# INLINE foldl'Build #-}
508{-# INLINE foldl'Build #-}
484foldl'Build :: Monad m => SerialT m Int -> m [Int]
509foldl'Build :: Monad m => SerialT m Int -> m [Int]
485foldl'Build = S.foldl' (flip (:)) []
510foldl'Build = S.foldl' (flip (:)) []
@@ -499,6 +524,7 @@ o_n_heap_elimination_foldl value =
499 , benchIdentitySink value "foldlM'/build/Identity" foldlM'Build
524 , benchIdentitySink value "foldlM'/build/Identity" foldlM'Build
500 ]
525 ]
501 ]
526 ]
527+#endif
502
528
503-- For comparisons
529-- For comparisons
504{-# INLINE showInstanceList #-}
530{-# INLINE showInstanceList #-}
@@ -533,7 +559,7 @@ o_n_space_elimination_foldr value =
533 , benchIOSink value "foldrM/reduce/IO (sum)" foldrMReduce
559 , benchIOSink value "foldrM/reduce/IO (sum)" foldrMReduce
534 ]
560 ]
535 ]
561 ]
536−
562+#ifdef USE_PRELUDE
537o_n_heap_elimination_toList :: Int -> [Benchmark]
563o_n_heap_elimination_toList :: Int -> [Benchmark]
538o_n_heap_elimination_toList value =
564o_n_heap_elimination_toList value =
539 [ bgroup "toList"
565 [ bgroup "toList"
@@ -553,7 +579,7 @@ o_n_space_elimination_toList value =
553 (Internal.toStream :: (SerialT IO Int -> IO (SerialT Identity Int)))
579 (Internal.toStream :: (SerialT IO Int -> IO (SerialT Identity Int)))
554 ]
580 ]
555 ]
581 ]
556−
582+#endif
557-------------------------------------------------------------------------------
583-------------------------------------------------------------------------------
558-- Multi-stream folds
584-- Multi-stream folds
559-------------------------------------------------------------------------------
585-------------------------------------------------------------------------------
@@ -673,14 +699,17 @@ benchmarks moduleName size =
673 , o_1_space_elimination_multi_stream_pure size
699 , o_1_space_elimination_multi_stream_pure size
674 , o_1_space_elimination_multi_stream size
700 , o_1_space_elimination_multi_stream size
675 ]
701 ]
702+
676− , bgroup (o_n_heap_prefix moduleName) $ concat
703+ , bgroup (o_n_heap_prefix moduleName) $
704+ o_n_heap_elimination_buffered size
705+#ifdef USE_PRELUDE
677− [ o_n_heap_elimination_foldl size
706+ ++ o_n_heap_elimination_foldl size
678− , o_n_heap_elimination_toList size
707+ ++ o_n_heap_elimination_toList size
679− , o_n_heap_elimination_buffered size
708+#endif
680− ]
681− , bgroup (o_n_space_prefix moduleName) $ concat
709+ , bgroup (o_n_space_prefix moduleName) $
682− [ o_n_space_elimination_foldable size
710+ o_n_space_elimination_foldable size
711+#ifdef USE_PRELUDE
683− , o_n_space_elimination_toList size
712+ ++ o_n_space_elimination_toList size
713+#endif
684− , o_n_space_elimination_foldr size
714+ ++ o_n_space_elimination_foldr size
685− ]
686 ]
715 ]
benchmark/Streamly/Benchmark/Prelude/Serial/Exceptions.hs → benchmark/Streamly/Benchmark/Data/Stream/Exceptions.hsrenamed+63−31
@@ -1,5 +1,5 @@
1-- |
1-- |
2−-- Module : Streamly.Benchmark.Prelude.Serial.Exceptions
2+-- Module : Stream.Exceptions
3-- Copyright : (c) 2019 Composewell Technologies
3-- Copyright : (c) 2019 Composewell Technologies
4-- License : BSD-3-Clause
4-- License : BSD-3-Clause
5-- Maintainer : streamly@composewell.com
5-- Maintainer : streamly@composewell.com
@@ -18,7 +18,7 @@
18{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
18{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
19#endif
19#endif
20
20
21−module Serial.Exceptions (benchmarks) where
21+module Stream.Exceptions (benchmarks) where
22
22
23import Control.Exception (SomeException, Exception, throwIO)
23import Control.Exception (SomeException, Exception, throwIO)
24import System.IO (Handle, hClose, hPutChar)
24import System.IO (Handle, hClose, hPutChar)
@@ -29,10 +29,18 @@ import qualified Data.Map.Strict as Map
29import qualified Streamly.FileSystem.Handle as FH
29import qualified Streamly.FileSystem.Handle as FH
30import qualified Streamly.Internal.Data.Unfold as IUF
30import qualified Streamly.Internal.Data.Unfold as IUF
31import qualified Streamly.Internal.FileSystem.Handle as IFH
31import qualified Streamly.Internal.FileSystem.Handle as IFH
32+#ifdef USE_PRELUDE
32−import qualified Streamly.Internal.Data.Stream.IsStream as IP
33+import qualified Streamly.Internal.Data.Stream.IsStream as Stream
33import qualified Streamly.Prelude as S
34import qualified Streamly.Prelude as S
35+#else
36+import qualified Streamly.Internal.Data.Stream as Stream
37+import qualified Streamly.Internal.Data.Stream as S
38+import qualified Streamly.Internal.Data.Fold as Fold
39+import qualified Streamly.Internal.Data.Unfold as Unfold
40+#endif
34
41
35import Gauge hiding (env)
42import Gauge hiding (env)
43+import Streamly.Internal.Data.Stream.Serial (SerialT)
36import Prelude hiding (last, length)
44import Prelude hiding (last, length)
37import Streamly.Benchmark.Common
45import Streamly.Benchmark.Common
38import Streamly.Benchmark.Common.Handle
46import Streamly.Benchmark.Common.Handle
@@ -47,6 +55,28 @@ import qualified Streamly.Internal.Data.Stream.StreamD as D
47-- stream exceptions
55-- stream exceptions
48-------------------------------------------------------------------------------
56-------------------------------------------------------------------------------
49
57
58+drain :: SerialT IO a -> IO ()
59+#ifdef USE_PRELUDE
60+drain = Stream.drain
61+#else
62+drain = Stream.fold Fold.drain
63+#endif
64+
65+enumerateFromTo :: Int -> Int -> SerialT IO Int
66+#ifdef USE_PRELUDE
67+enumerateFromTo length from = S.enumerateFromTo from (from + length)
68+#else
69+enumerateFromTo length from = Stream.unfold Unfold.enumerateFromTo (from, from + length)
70+#endif
71+
72+sourceRef :: (Num b) => Int -> Int -> Ref.IORef b -> SerialT IO b
73+#ifdef USE_PRELUDE
74+sourceRef length from ref = S.replicateM (from + length)
75+#else
76+sourceRef length from ref = Stream.unfold (Unfold.replicateM (from + length))
77+#endif
78+ $ Ref.modifyIORef' ref (+ 1) >> Ref.readIORef ref
79+
50data BenchException
80data BenchException
51 = BenchException1
81 = BenchException1
52 | BenchException2
82 | BenchException2
@@ -56,37 +86,40 @@ instance Exception BenchException
56
86
57retryNoneSimple :: Int -> Int -> IO ()
87retryNoneSimple :: Int -> Int -> IO ()
58retryNoneSimple length from =
88retryNoneSimple length from =
59− IP.drain
89+ drain
90+ $ Stream.retry
60− $ IP.retry (Map.singleton BenchException1 length) (const S.nil) source
91+ (Map.singleton BenchException1 length)
92+ (const S.nil)
93+ source
61
94
62 where
95 where
63
96
64− source = S.enumerateFromTo from (from + length)
97+ source = enumerateFromTo length from
65
98
66retryNone :: Int -> Int -> IO ()
99retryNone :: Int -> Int -> IO ()
67retryNone length from = do
100retryNone length from = do
68 ref <- Ref.newIORef (0 :: Int)
101 ref <- Ref.newIORef (0 :: Int)
69− IP.drain
102+ drain
70− $ IP.retry (Map.singleton BenchException1 length) (const S.nil)
103+ $ Stream.retry (Map.singleton BenchException1 length) (const S.nil)
71 $ source ref
104 $ source ref
72
105
73 where
106 where
74
107
75− source ref =
108+ source = sourceRef length from
76− IP.replicateM (from + length)
109+
77− $ Ref.modifyIORef' ref (+ 1) >> Ref.readIORef ref
78
110
79retryAll :: Int -> Int -> IO ()
111retryAll :: Int -> Int -> IO ()
80retryAll length from = do
112retryAll length from = do
81 ref <- Ref.newIORef 0
113 ref <- Ref.newIORef 0
82− IP.drain
114+ drain
115+ $ Stream.retry
83− $ IP.retry (Map.singleton BenchException1 (length + from)) (const S.nil)
116+ (Map.singleton BenchException1 (length + from)) (const S.nil)
84 $ source ref
117 $ source ref
85
118
86 where
119 where
87
120
88 source ref =
121 source ref =
89− IP.fromEffect
122+ Stream.fromEffect
90 $ do
123 $ do
91 Ref.modifyIORef' ref (+ 1)
124 Ref.modifyIORef' ref (+ 1)
92 val <- Ref.readIORef ref
125 val <- Ref.readIORef ref
@@ -96,13 +129,13 @@ retryAll length from = do
96
129
97retryUnknown :: Int -> Int -> IO ()
130retryUnknown :: Int -> Int -> IO ()
98retryUnknown length from = do
131retryUnknown length from = do
99− IP.drain
132+ drain
100− $ IP.retry (Map.singleton BenchException1 length) (const source)
133+ $ Stream.retry (Map.singleton BenchException1 length) (const source)
101 $ throwIO BenchException2 `S.before` S.nil
134 $ throwIO BenchException2 `S.before` S.nil
102
135
103 where
136 where
104
137
105− source = S.enumerateFromTo from (from + length)
138+ source = enumerateFromTo length from
106
139
107
140
108o_1_space_serial_exceptions :: Int -> [Benchmark]
141o_1_space_serial_exceptions :: Int -> [Benchmark]
@@ -124,7 +157,7 @@ o_1_space_serial_exceptions length =
124readWriteOnExceptionStream :: Handle -> Handle -> IO ()
157readWriteOnExceptionStream :: Handle -> Handle -> IO ()
125readWriteOnExceptionStream inh devNull =
158readWriteOnExceptionStream inh devNull =
126 let readEx = S.onException (hClose inh) (S.unfold FH.read inh)
159 let readEx = S.onException (hClose inh) (S.unfold FH.read inh)
127− in S.fold (FH.write devNull) $ readEx
160+ in S.fold (FH.write devNull) readEx
128
161
129#ifdef INSPECTION
162#ifdef INSPECTION
130inspect $ hasNoTypeClasses 'readWriteOnExceptionStream
163inspect $ hasNoTypeClasses 'readWriteOnExceptionStream
@@ -135,7 +168,7 @@ readWriteHandleExceptionStream :: Handle -> Handle -> IO ()
135readWriteHandleExceptionStream inh devNull =
168readWriteHandleExceptionStream inh devNull =
136 let handler (_e :: SomeException) = S.fromEffect (hClose inh >> return 10)
169 let handler (_e :: SomeException) = S.fromEffect (hClose inh >> return 10)
137 readEx = S.handle handler (S.unfold FH.read inh)
170 readEx = S.handle handler (S.unfold FH.read inh)
138− in S.fold (FH.write devNull) $ readEx
171+ in S.fold (FH.write devNull) readEx
139
172
140#ifdef INSPECTION
173#ifdef INSPECTION
141inspect $ hasNoTypeClasses 'readWriteHandleExceptionStream
174inspect $ hasNoTypeClasses 'readWriteHandleExceptionStream
@@ -144,7 +177,7 @@ inspect $ hasNoTypeClasses 'readWriteHandleExceptionStream
144-- | Send the file contents to /dev/null with exception handling
177-- | Send the file contents to /dev/null with exception handling
145readWriteFinally_Stream :: Handle -> Handle -> IO ()
178readWriteFinally_Stream :: Handle -> Handle -> IO ()
146readWriteFinally_Stream inh devNull =
179readWriteFinally_Stream inh devNull =
147− let readEx = IP.finally_ (hClose inh) (S.unfold FH.read inh)
180+ let readEx = Stream.finally_ (hClose inh) (S.unfold FH.read inh)
148 in S.fold (FH.write devNull) readEx
181 in S.fold (FH.write devNull) readEx
149
182
150#ifdef INSPECTION
183#ifdef INSPECTION
@@ -159,9 +192,9 @@ readWriteFinallyStream inh devNull =
159-- | Send the file contents to /dev/null with exception handling
192-- | Send the file contents to /dev/null with exception handling
160fromToBytesBracket_Stream :: Handle -> Handle -> IO ()
193fromToBytesBracket_Stream :: Handle -> Handle -> IO ()
161fromToBytesBracket_Stream inh devNull =
194fromToBytesBracket_Stream inh devNull =
162− let readEx = IP.bracket_ (return ()) (\_ -> hClose inh)
195+ let readEx = Stream.bracket_ (return ()) (\_ -> hClose inh)
163 (\_ -> IFH.getBytes inh)
196 (\_ -> IFH.getBytes inh)
164− in IFH.putBytes devNull $ readEx
197+ in IFH.putBytes devNull readEx
165
198
166#ifdef INSPECTION
199#ifdef INSPECTION
167inspect $ hasNoTypeClasses 'fromToBytesBracket_Stream
200inspect $ hasNoTypeClasses 'fromToBytesBracket_Stream
@@ -171,13 +204,13 @@ fromToBytesBracketStream :: Handle -> Handle -> IO ()
171fromToBytesBracketStream inh devNull =
204fromToBytesBracketStream inh devNull =
172 let readEx = S.bracket (return ()) (\_ -> hClose inh)
205 let readEx = S.bracket (return ()) (\_ -> hClose inh)
173 (\_ -> IFH.getBytes inh)
206 (\_ -> IFH.getBytes inh)
174− in IFH.putBytes devNull $ readEx
207+ in IFH.putBytes devNull readEx
175
208
176readWriteBeforeAfterStream :: Handle -> Handle -> IO ()
209readWriteBeforeAfterStream :: Handle -> Handle -> IO ()
177readWriteBeforeAfterStream inh devNull =
210readWriteBeforeAfterStream inh devNull =
178 let readEx =
211 let readEx =
179− IP.after (hClose inh)
212+ Stream.after (hClose inh)
180− $ IP.before (hPutChar devNull 'A') (S.unfold FH.read inh)
213+ $ Stream.before (hPutChar devNull 'A') (S.unfold FH.read inh)
181 in S.fold (FH.write devNull) readEx
214 in S.fold (FH.write devNull) readEx
182
215
183#ifdef INSPECTION
216#ifdef INSPECTION
@@ -186,7 +219,7 @@ inspect $ 'readWriteBeforeAfterStream `hasNoType` ''D.Step
186
219
187readWriteAfterStream :: Handle -> Handle -> IO ()
220readWriteAfterStream :: Handle -> Handle -> IO ()
188readWriteAfterStream inh devNull =
221readWriteAfterStream inh devNull =
189− let readEx = IP.after (hClose inh) (S.unfold FH.read inh)
222+ let readEx = Stream.after (hClose inh) (S.unfold FH.read inh)
190 in S.fold (FH.write devNull) readEx
223 in S.fold (FH.write devNull) readEx
191
224
192#ifdef INSPECTION
225#ifdef INSPECTION
@@ -195,7 +228,7 @@ inspect $ 'readWriteAfterStream `hasNoType` ''D.Step
195
228
196readWriteAfter_Stream :: Handle -> Handle -> IO ()
229readWriteAfter_Stream :: Handle -> Handle -> IO ()
197readWriteAfter_Stream inh devNull =
230readWriteAfter_Stream inh devNull =
198− let readEx = IP.after_ (hClose inh) (S.unfold FH.read inh)
231+ let readEx = Stream.after_ (hClose inh) (S.unfold FH.read inh)
199 in S.fold (FH.write devNull) readEx
232 in S.fold (FH.write devNull) readEx
200
233
201#ifdef INSPECTION
234#ifdef INSPECTION
@@ -277,11 +310,11 @@ o_1_space_copy_exceptions_readChunks env =
277-- | Send the file contents to /dev/null with exception handling
310-- | Send the file contents to /dev/null with exception handling
278toChunksBracket_ :: Handle -> Handle -> IO ()
311toChunksBracket_ :: Handle -> Handle -> IO ()
279toChunksBracket_ inh devNull =
312toChunksBracket_ inh devNull =
280− let readEx = IP.bracket_
313+ let readEx = Stream.bracket_
281 (return ())
314 (return ())
282 (\_ -> hClose inh)
315 (\_ -> hClose inh)
283 (\_ -> IFH.getChunks inh)
316 (\_ -> IFH.getChunks inh)
284− in S.fold (IFH.writeChunks devNull) $ readEx
317+ in S.fold (IFH.writeChunks devNull) readEx
285
318
286#ifdef INSPECTION
319#ifdef INSPECTION
287inspect $ hasNoTypeClasses 'toChunksBracket_
320inspect $ hasNoTypeClasses 'toChunksBracket_
@@ -293,7 +326,7 @@ toChunksBracket inh devNull =
293 (return ())
326 (return ())
294 (\_ -> hClose inh)
327 (\_ -> hClose inh)
295 (\_ -> IFH.getChunks inh)
328 (\_ -> IFH.getChunks inh)
296− in S.fold (IFH.writeChunks devNull) $ readEx
329+ in S.fold (IFH.writeChunks devNull) readEx
297
330
298o_1_space_copy_exceptions_toChunks :: BenchEnv -> [Benchmark]
331o_1_space_copy_exceptions_toChunks :: BenchEnv -> [Benchmark]
299o_1_space_copy_exceptions_toChunks env =
332o_1_space_copy_exceptions_toChunks env =
@@ -305,7 +338,6 @@ o_1_space_copy_exceptions_toChunks env =
305 ]
338 ]
306 ]
339 ]
307
340
308−
309benchmarks :: String -> BenchEnv -> Int -> [Benchmark]
341benchmarks :: String -> BenchEnv -> Int -> [Benchmark]
310benchmarks moduleName env size =
342benchmarks moduleName env size =
311 [ bgroup (o_1_space_prefix moduleName) $ concat
343 [ bgroup (o_1_space_prefix moduleName) $ concat
benchmark/Streamly/Benchmark/Prelude/Serial/Generation.hs → benchmark/Streamly/Benchmark/Data/Stream/Generate.hsrenamed+60−11
@@ -1,5 +1,5 @@
1-- |
1-- |
2−-- Module : Serial.Generation
2+-- Module : Stream.Generate
3-- Copyright : (c) 2018 Composewell Technologies
3-- Copyright : (c) 2018 Composewell Technologies
4-- License : BSD-3-Clause
4-- License : BSD-3-Clause
5-- Maintainer : streamly@composewell.com
5-- Maintainer : streamly@composewell.com
@@ -9,19 +9,29 @@
9{-# LANGUAGE ScopedTypeVariables #-}
9{-# LANGUAGE ScopedTypeVariables #-}
10{-# LANGUAGE RankNTypes #-}
10{-# LANGUAGE RankNTypes #-}
11
11
12−module Serial.Generation (benchmarks) where
12+module Stream.Generate (benchmarks) where
13
13
14import Data.Functor.Identity (Identity)
14import Data.Functor.Identity (Identity)
15
15
16−import qualified Prelude
16+#ifdef USE_PRELUDE
17import qualified GHC.Exts as GHC
17import qualified GHC.Exts as GHC
18−
19−import qualified Streamly.Prelude as S
18+import qualified Streamly.Prelude as S
19+import qualified Prelude
20+#endif
21+import qualified Streamly.Internal.Data.Stream as Stream
22+import qualified Streamly.Internal.Data.Unfold as Unfold
20
23
21import Gauge
24import Gauge
22−import Streamly.Prelude (SerialT, fromSerial, MonadAsync)
23import Streamly.Benchmark.Common
25import Streamly.Benchmark.Common
26+import Streamly.Internal.Data.Stream.Serial (SerialT)
27+#ifdef USE_PRELUDE
24import Streamly.Benchmark.Prelude
28import Streamly.Benchmark.Prelude
29+import Streamly.Prelude (fromSerial, MonadAsync)
30+#endif
31+import qualified Stream.Common as SC
32+
33+import System.IO.Unsafe (unsafeInterleaveIO)
34+
25import Prelude hiding (repeat, replicate, iterate)
35import Prelude hiding (repeat, replicate, iterate)
26
36
27-------------------------------------------------------------------------------
37-------------------------------------------------------------------------------
@@ -31,7 +41,7 @@ import Prelude hiding (repeat, replicate, iterate)
31-------------------------------------------------------------------------------
41-------------------------------------------------------------------------------
32-- fromList
42-- fromList
33-------------------------------------------------------------------------------
43-------------------------------------------------------------------------------
34−
44+#ifdef USE_PRELUDE
35{-# INLINE sourceIsList #-}
45{-# INLINE sourceIsList #-}
36sourceIsList :: Int -> Int -> SerialT Identity Int
46sourceIsList :: Int -> Int -> SerialT Identity Int
37sourceIsList value n = GHC.fromList [n..n+value]
47sourceIsList value n = GHC.fromList [n..n+value]
@@ -39,6 +49,7 @@ sourceIsList value n = GHC.fromList [n..n+value]
39{-# INLINE sourceIsString #-}
49{-# INLINE sourceIsString #-}
40sourceIsString :: Int -> Int -> SerialT Identity Char
50sourceIsString :: Int -> Int -> SerialT Identity Char
41sourceIsString value n = GHC.fromString (Prelude.replicate (n + value) 'a')
51sourceIsString value n = GHC.fromString (Prelude.replicate (n + value) 'a')
52+#endif
42
53
43{-# INLINE readInstance #-}
54{-# INLINE readInstance #-}
44readInstance :: String -> SerialT Identity Int
55readInstance :: String -> SerialT Identity Int
@@ -57,6 +68,7 @@ readInstanceList str =
57 [(x,"")] -> x
68 [(x,"")] -> x
58 _ -> error "readInstance: no parse"
69 _ -> error "readInstance: no parse"
59
70
71+#ifdef USE_PRELUDE
60{-# INLINE repeat #-}
72{-# INLINE repeat #-}
61repeat :: (Monad m, S.IsStream t) => Int -> Int -> t m Int
73repeat :: (Monad m, S.IsStream t) => Int -> Int -> t m Int
62repeat count = S.take count . S.repeat
74repeat count = S.take count . S.repeat
@@ -115,8 +127,8 @@ fromIndices value n = S.take value $ S.fromIndices (+ n)
115fromIndicesM :: (MonadAsync m, S.IsStream t) => Int -> Int -> t m Int
127fromIndicesM :: (MonadAsync m, S.IsStream t) => Int -> Int -> t m Int
116fromIndicesM value n = S.take value $ S.fromIndicesM (return <$> (+ n))
128fromIndicesM value n = S.take value $ S.fromIndicesM (return <$> (+ n))
117
129
118−o_1_space_generation :: Int -> [Benchmark]
130+o_1_space_generation_prel :: Int -> [Benchmark]
119−o_1_space_generation value =
131+o_1_space_generation_prel value =
120 [ bgroup "generation"
132 [ bgroup "generation"
121 [ benchIOSrc fromSerial "unfoldr" (sourceUnfoldr value)
133 [ benchIOSrc fromSerial "unfoldr" (sourceUnfoldr value)
122 , benchIOSrc fromSerial "unfoldrM" (sourceUnfoldrM value)
134 , benchIOSrc fromSerial "unfoldrM" (sourceUnfoldrM value)
@@ -147,10 +159,42 @@ o_1_space_generation value =
147 -- These essentially test cons and consM
159 -- These essentially test cons and consM
148 , benchIOSrc fromSerial "fromFoldable" (sourceFromFoldable value)
160 , benchIOSrc fromSerial "fromFoldable" (sourceFromFoldable value)
149 , benchIOSrc fromSerial "fromFoldableM" (sourceFromFoldableM value)
161 , benchIOSrc fromSerial "fromFoldableM" (sourceFromFoldableM value)
150−
151 , benchIOSrc fromSerial "absTimes" $ absTimes value
162 , benchIOSrc fromSerial "absTimes" $ absTimes value
152 ]
163 ]
153 ]
164 ]
165+#endif
166+
167+{-# INLINE mfixUnfold #-}
168+mfixUnfold :: Int -> Int -> SerialT IO (Int, Int)
169+mfixUnfold count start = Stream.mfix f
170+ where
171+ f action = do
172+ let incr n act = fmap ((+n) . snd) $ unsafeInterleaveIO act
173+ x <- Stream.unfold Unfold.fromListM [incr 1 action, incr 2 action]
174+ y <- SC.sourceUnfoldr count start
175+ return (x, y)
176+
177+{-# INLINE fromFoldable #-}
178+fromFoldable :: Int -> Int -> SerialT m Int
179+fromFoldable count start =
180+ Stream.fromFoldable (Prelude.enumFromTo count start)
181+
182+{-# INLINE fromFoldableM #-}
183+fromFoldableM :: Monad m => Int -> Int -> SerialT m Int
184+fromFoldableM count start =
185+ Stream.fromFoldableM (fmap return (Prelude.enumFromTo count start))
186+
187+o_1_space_generation :: Int -> [Benchmark]
188+o_1_space_generation value =
189+ [ bgroup "generation"
190+ [ SC.benchIOSrc "unfold" (SC.sourceUnfoldr value)
191+ , SC.benchIOSrc "fromFoldable" (fromFoldable value)
192+ , SC.benchIOSrc "fromFoldableM" (fromFoldableM value)
193+ , SC.benchIOSrc "mfix_10" (mfixUnfold 10)
194+ , SC.benchIOSrc "mfix_100" (mfixUnfold 100)
195+ , SC.benchIOSrc "mfix_1000" (mfixUnfold 1000)
196+ ]
197+ ]
154
198
155o_n_heap_generation :: Int -> [Benchmark]
199o_n_heap_generation :: Int -> [Benchmark]
156o_n_heap_generation value =
200o_n_heap_generation value =
@@ -174,6 +218,11 @@ o_n_heap_generation value =
174--
218--
175benchmarks :: String -> Int -> [Benchmark]
219benchmarks :: String -> Int -> [Benchmark]
176benchmarks moduleName size =
220benchmarks moduleName size =
221+ [
222+#ifdef USE_PRELUDE
223+ bgroup (o_1_space_prefix moduleName) (o_1_space_generation_prel size)
224+ ,
225+#endif
177− [ bgroup (o_1_space_prefix moduleName) (o_1_space_generation size)
226+ bgroup (o_1_space_prefix moduleName) (o_1_space_generation size)
178 , bgroup (o_n_heap_prefix moduleName) (o_n_heap_generation size)
227 , bgroup (o_n_heap_prefix moduleName) (o_n_heap_generation size)
179 ]
228 ]
benchmark/Streamly/Benchmark/Prelude/Serial/Lift.hs → benchmark/Streamly/Benchmark/Data/Stream/Lift.hsrenamed+58−18
@@ -1,5 +1,5 @@
1-- |
1-- |
2−-- Module : Serial.Lift
2+-- Module : Stream.Lift
3-- Copyright : (c) 2018 Composewell Technologies
3-- Copyright : (c) 2018 Composewell Technologies
4-- License : BSD-3-Clause
4-- License : BSD-3-Clause
5-- Maintainer : streamly@composewell.com
5-- Maintainer : streamly@composewell.com
@@ -9,29 +9,38 @@
9{-# LANGUAGE ScopedTypeVariables #-}
9{-# LANGUAGE ScopedTypeVariables #-}
10{-# LANGUAGE RankNTypes #-}
10{-# LANGUAGE RankNTypes #-}
11
11
12−module Serial.Lift (benchmarks) where
12+module Stream.Lift (benchmarks) where
13
13
14+#ifdef USE_PRELUDE
15+import Control.Monad.Trans.Class (lift)
14import Control.Monad.State.Strict (StateT, get, put, MonadState)
16import Control.Monad.State.Strict (StateT, get, put, MonadState)
17+import Streamly.Prelude (fromSerial)
18+import Streamly.Benchmark.Prelude
15import qualified Control.Monad.State.Strict as State
19import qualified Control.Monad.State.Strict as State
16−import Control.Monad.Trans.Class (lift)
17−
18−import qualified Streamly.Prelude as S
20+import qualified Streamly.Prelude as Stream
19import qualified Streamly.Internal.Data.Stream.IsStream as Internal
21import qualified Streamly.Internal.Data.Stream.IsStream as Internal
22+#else
23+import Control.DeepSeq (NFData(..))
24+import Data.Functor.Identity (Identity)
25+import Stream.Common (sourceUnfoldr, sourceUnfoldrM, benchIOSrc)
26+import System.Random (randomRIO)
27+import qualified Streamly.Internal.Data.Stream as Stream
28+#endif
20
29
21import Gauge
30import Gauge
22−import Streamly.Prelude (SerialT, fromSerial)
31+import Streamly.Internal.Data.Stream.Serial (SerialT)
23import Streamly.Benchmark.Common
32import Streamly.Benchmark.Common
24−import Streamly.Benchmark.Prelude
33+
25import Prelude hiding (reverse, tail)
34import Prelude hiding (reverse, tail)
26
35
27-------------------------------------------------------------------------------
36-------------------------------------------------------------------------------
28-- Monad transformation (hoisting etc.)
37-- Monad transformation (hoisting etc.)
29-------------------------------------------------------------------------------
38-------------------------------------------------------------------------------
30−
39+#ifdef USE_PRELUDE
31{-# INLINE sourceUnfoldrState #-}
40{-# INLINE sourceUnfoldrState #-}
32−sourceUnfoldrState :: (S.IsStream t, S.MonadAsync m)
41+sourceUnfoldrState :: (Stream.IsStream t, Stream.MonadAsync m)
33 => Int -> Int -> t (StateT Int m) Int
42 => Int -> Int -> t (StateT Int m) Int
34−sourceUnfoldrState value n = S.unfoldrM step n
43+sourceUnfoldrState value n = Stream.unfoldrM step n
35 where
44 where
36 step cnt =
45 step cnt =
37 if cnt > n + value
46 if cnt > n + value
@@ -42,12 +51,12 @@ sourceUnfoldrState value n = S.unfoldrM step n
42 return (Just (s, cnt + 1))
51 return (Just (s, cnt + 1))
43
52
44{-# INLINE evalStateT #-}
53{-# INLINE evalStateT #-}
45−evalStateT :: S.MonadAsync m => Int -> Int -> SerialT m Int
54+evalStateT :: Stream.MonadAsync m => Int -> Int -> SerialT m Int
46evalStateT value n =
55evalStateT value n =
47 Internal.evalStateT (return 0) (sourceUnfoldrState value n)
56 Internal.evalStateT (return 0) (sourceUnfoldrState value n)
48
57
49{-# INLINE withState #-}
58{-# INLINE withState #-}
50−withState :: S.MonadAsync m => Int -> Int -> SerialT m Int
59+withState :: Stream.MonadAsync m => Int -> Int -> SerialT m Int
51withState value n =
60withState value n =
52 Internal.evalStateT
61 Internal.evalStateT
53 (return (0 :: Int)) (Internal.liftInner (sourceUnfoldrM value n))
62 (return (0 :: Int)) (Internal.liftInner (sourceUnfoldrM value n))
@@ -62,7 +71,7 @@ o_1_space_hoisting value =
62
71
63{-# INLINE iterateStateIO #-}
72{-# INLINE iterateStateIO #-}
64iterateStateIO ::
73iterateStateIO ::
65− (S.MonadAsync m)
74+ (Stream.MonadAsync m)
66 => Int
75 => Int
67 -> StateT Int m Int
76 -> StateT Int m Int
68iterateStateIO n = do
77iterateStateIO n = do
@@ -86,7 +95,7 @@ iterateStateT n = do
86{-# INLINE iterateState #-}
95{-# INLINE iterateState #-}
87{-# SPECIALIZE iterateState :: Int -> SerialT (StateT Int IO) Int #-}
96{-# SPECIALIZE iterateState :: Int -> SerialT (StateT Int IO) Int #-}
88iterateState ::
97iterateState ::
89− (S.MonadAsync m, MonadState Int m)
98+ (Stream.MonadAsync m, MonadState Int m)
90 => Int
99 => Int
91 -> SerialT m Int
100 -> SerialT m Int
92iterateState n = do
101iterateState n = do
@@ -103,12 +112,38 @@ o_n_heap_transformer value =
103 [ benchIO "StateT Int IO (n times) (baseline)" $ \n ->
112 [ benchIO "StateT Int IO (n times) (baseline)" $ \n ->
104 State.evalStateT (iterateStateIO n) value
113 State.evalStateT (iterateStateIO n) value
105 , benchIO "SerialT (StateT Int IO) (n times)" $ \n ->
114 , benchIO "SerialT (StateT Int IO) (n times)" $ \n ->
106− State.evalStateT (S.drain (iterateStateT n)) value
115+ State.evalStateT (Stream.drain (iterateStateT n)) value
107 , benchIO "MonadState Int m => SerialT m Int" $ \n ->
116 , benchIO "MonadState Int m => SerialT m Int" $ \n ->
108− State.evalStateT (S.drain (iterateState n)) value
117+ State.evalStateT (Stream.drain (iterateState n)) value
109 ]
118 ]
110 ]
119 ]
111−
120+#else
121+{-# INLINE benchHoistSink #-}
122+benchHoistSink
123+ :: (NFData b)
124+ => Int -> String -> (SerialT Identity Int -> IO b) -> Benchmark
125+benchHoistSink value name f =
126+ bench name $ nfIO $ randomRIO (1,1) >>= f . sourceUnfoldr value
127+
128+-- XXX We should be using sourceUnfoldrM for fair comparison with IO monad, but
129+-- we can't use it as it requires MonadAsync constraint.
130+
131+{-# INLINE liftInner #-}
132+liftInner :: Monad m => Int -> Int -> SerialT m Int
133+liftInner value n =
134+ Stream.evalStateT
135+ (return (0 :: Int)) (Stream.liftInner (sourceUnfoldrM value n))
136+
137+o_1_space_generation :: Int -> [Benchmark]
138+o_1_space_generation value =
139+ [ bgroup "lift"
140+ [ benchHoistSink value "length . generally"
141+ ((\(_ :: SerialT IO Int) -> return 8 :: IO Int) . Stream.generally)
142+
143+ , benchIOSrc "liftInner/evalStateT" (liftInner value)
144+ ]
145+ ]
146+#endif
112-------------------------------------------------------------------------------
147-------------------------------------------------------------------------------
113-- Main
148-- Main
114-------------------------------------------------------------------------------
149-------------------------------------------------------------------------------
@@ -118,6 +153,11 @@ o_n_heap_transformer value =
118--
153--
119benchmarks :: String -> Int -> [Benchmark]
154benchmarks :: String -> Int -> [Benchmark]
120benchmarks moduleName size =
155benchmarks moduleName size =
156+ [
157+#ifdef USE_PRELUDE
121− [ bgroup (o_1_space_prefix moduleName) (o_1_space_hoisting size)
158+ bgroup (o_1_space_prefix moduleName) (o_1_space_hoisting size)
122 , bgroup (o_n_heap_prefix moduleName) (o_n_heap_transformer size)
159 , bgroup (o_n_heap_prefix moduleName) (o_n_heap_transformer size)
160+#else
161+ bgroup (o_1_space_prefix moduleName) (o_1_space_generation size)
162+#endif
123 ]
163 ]
benchmark/Streamly/Benchmark/Prelude/Serial/NestedFold.hs → benchmark/Streamly/Benchmark/Data/Stream/NestedFold.hsrenamed+2−2
@@ -1,5 +1,5 @@
1-- |
1-- |
2−-- Module : Serial.NestedFold
2+-- Module : Stream.NestedFold
3-- Copyright : (c) 2018 Composewell Technologies
3-- Copyright : (c) 2018 Composewell Technologies
4-- License : BSD-3-Clause
4-- License : BSD-3-Clause
5-- Maintainer : streamly@composewell.com
5-- Maintainer : streamly@composewell.com
@@ -11,7 +11,7 @@
11{-# LANGUAGE DeriveGeneric #-}
11{-# LANGUAGE DeriveGeneric #-}
12{-# LANGUAGE RankNTypes #-}
12{-# LANGUAGE RankNTypes #-}
13
13
14−module Serial.NestedFold (benchmarks) where
14+module Stream.NestedFold (benchmarks) where
15
15
16import Control.DeepSeq (NFData(..))
16import Control.DeepSeq (NFData(..))
17import Control.Monad (when)
17import Control.Monad (when)
benchmark/Streamly/Benchmark/Prelude/Serial/NestedStream.hs → benchmark/Streamly/Benchmark/Data/Stream/NestedStream.hsrenamed+3−3
@@ -1,5 +1,5 @@
1-- |
1-- |
2−-- Module : Serial.NestedStream
2+-- Module : Stream.NestedStream
3-- Copyright : (c) 2018 Composewell Technologies
3-- Copyright : (c) 2018 Composewell Technologies
4-- License : BSD-3-Clause
4-- License : BSD-3-Clause
5-- Maintainer : streamly@composewell.com
5-- Maintainer : streamly@composewell.com
@@ -18,7 +18,7 @@
18{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
18{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
19#endif
19#endif
20
20
21−module Serial.NestedStream (benchmarks) where
21+module Stream.NestedStream (benchmarks) where
22
22
23import Control.Monad.Trans.Class (lift)
23import Control.Monad.Trans.Class (lift)
24
24
@@ -356,7 +356,7 @@ o_n_space_applicative value =
356 [ benchIOSrc fromSerial "(*>) (n times)" $
356 [ benchIOSrc fromSerial "(*>) (n times)" $
357 iterateSingleton ((*>) . pure) value
357 iterateSingleton ((*>) . pure) value
358 , benchIOSrc fromSerial "(<*) (n times)" $
358 , benchIOSrc fromSerial "(<*) (n times)" $
359− iterateSingleton (\x xs -> xs <* pure x) value
359+ iterateSingleton (\x xs -> xs <* pure x) value
360 , benchIOSrc fromSerial "(<*>) (n times)" $
360 , benchIOSrc fromSerial "(<*>) (n times)" $
361 iterateSingleton (\x xs -> pure (+ x) <*> xs) value
361 iterateSingleton (\x xs -> pure (+ x) <*> xs) value
362 , benchIOSrc fromSerial "liftA2 (n times)" $
362 , benchIOSrc fromSerial "liftA2 (n times)" $
benchmark/Streamly/Benchmark/Data/Stream/Reduce.hsnew file+124
@@ -0,0 +1,124 @@
1+-- |
2+-- Module : Stream.Reduce
3+-- Copyright : (c) 2018 Composewell Technologies
4+-- License : BSD-3-Clause
5+-- Maintainer : streamly@composewell.com
6+
7+{-# LANGUAGE CPP #-}
8+{-# LANGUAGE FlexibleContexts #-}
9+{-# LANGUAGE ScopedTypeVariables #-}
10+{-# LANGUAGE RankNTypes #-}
11+
12+module Stream.Reduce (benchmarks) where
13+
14+import Control.Monad.Catch (MonadCatch)
15+import Data.Monoid (Sum(Sum), getSum)
16+import Stream.Common (benchIOSink)
17+import Streamly.Benchmark.Common (o_1_space_prefix)
18+import Streamly.Internal.Data.Stream (Stream)
19+
20+import qualified Streamly.Internal.Data.Stream as Stream
21+import qualified Streamly.Internal.Data.Parser as PR
22+import qualified Streamly.Internal.Data.Parser.ParserD as ParserD
23+
24+import Prelude hiding (length, sum, or, and, any, all, notElem, elem, (!!),
25+ lookup, repeat, minimum, maximum, product, last, mapM_, init)
26+
27+import Gauge
28+
29+import qualified Streamly.Data.Fold as FL
30+import qualified Streamly.Internal.Data.Refold.Type as Refold
31+import Control.Monad.IO.Class (MonadIO)
32+
33+{-# INLINE foldMany #-}
34+foldMany :: Monad m => Stream m Int -> m ()
35+foldMany =
36+ Stream.fold FL.drain
37+ . fmap getSum
38+ . Stream.foldMany (FL.take 2 FL.mconcat)
39+ . fmap Sum
40+
41+{-# INLINE foldManyPost #-}
42+foldManyPost :: Monad m => Stream m Int -> m ()
43+foldManyPost =
44+ Stream.fold FL.drain
45+ . fmap getSum
46+ . Stream.foldManyPost (FL.take 2 FL.mconcat)
47+ . fmap Sum
48+
49+{-# INLINE refoldMany #-}
50+refoldMany :: Monad m => Stream m Int -> m ()
51+refoldMany =
52+ Stream.fold FL.drain
53+ . fmap getSum
54+ . Stream.refoldMany (Refold.take 2 Refold.sconcat) (return mempty)
55+ . fmap Sum
56+
57+{-# INLINE foldIterateM #-}
58+foldIterateM :: Monad m => Stream m Int -> m ()
59+foldIterateM =
60+ Stream.fold FL.drain
61+ . fmap getSum
62+ . Stream.foldIterateM
63+ (return . FL.take 2 . FL.sconcat) (return (Sum 0))
64+ . fmap Sum
65+
66+{-# INLINE refoldIterateM #-}
67+refoldIterateM :: Monad m => Stream m Int -> m ()
68+refoldIterateM =
69+ Stream.fold FL.drain
70+ . fmap getSum
71+ . Stream.refoldIterateM
72+ (Refold.take 2 Refold.sconcat) (return (Sum 0))
73+ . fmap Sum
74+
75+{-# INLINE parseMany #-}
76+parseMany :: MonadCatch m => Int -> Stream m Int -> m ()
77+parseMany n =
78+ Stream.fold FL.drain
79+ . fmap getSum
80+ . Stream.parseMany (PR.fromFold $ FL.take n FL.mconcat)
81+ . fmap Sum
82+
83+{-# INLINE parseManyD #-}
84+parseManyD :: MonadCatch m => Int -> Stream m Int -> m ()
85+parseManyD n =
86+ Stream.fold FL.drain
87+ . fmap getSum
88+ . Stream.parseManyD (ParserD.fromFold $ FL.take n FL.mconcat)
89+ . fmap Sum
90+
91+{-# INLINE parseIterate #-}
92+parseIterate :: MonadCatch m => Int -> Stream m Int -> m ()
93+parseIterate n =
94+ Stream.fold FL.drain
95+ . fmap getSum
96+ . Stream.parseIterate (\_ -> PR.fromFold $ FL.take n FL.mconcat) 0
97+ . fmap Sum
98+
99+{-# INLINE arraysOf #-}
100+arraysOf :: (MonadCatch m, MonadIO m) => Int -> Stream m Int -> m ()
101+arraysOf n =
102+ Stream.fold FL.drain
103+ . Stream.arraysOf n
104+
105+o_1_space_grouping :: Int -> [Benchmark]
106+o_1_space_grouping value =
107+ -- Buffering operations using heap proportional to group/window sizes.
108+ [ bgroup "reduce"
109+ [ benchIOSink value "foldMany" foldMany
110+ , benchIOSink value "foldManyPost" foldManyPost
111+ , benchIOSink value "refoldMany" refoldMany
112+ , benchIOSink value "foldIterateM" foldIterateM
113+ , benchIOSink value "refoldIterateM" refoldIterateM
114+ , benchIOSink value "parseMany" $ parseMany value
115+ , benchIOSink value "parseManyD" $ parseManyD value
116+ , benchIOSink value "parseIterate" $ parseIterate value
117+ , benchIOSink value "arraysOf" $ arraysOf value
118+ ]
119+ ]
120+
121+benchmarks :: String -> Int -> [Benchmark]
122+benchmarks moduleName size =
123+ [ bgroup (o_1_space_prefix moduleName) $ o_1_space_grouping size
124+ ]
benchmark/Streamly/Benchmark/Prelude/Serial/Split.hs → benchmark/Streamly/Benchmark/Data/Stream/Split.hsrenamed+2−2
@@ -1,5 +1,5 @@
1-- |
1-- |
2−-- Module : Streamly.Benchmark.Prelude.Serial.Split
2+-- Module : Stream.Split
3-- Copyright : (c) 2019 Composewell Technologies
3-- Copyright : (c) 2019 Composewell Technologies
4-- License : BSD-3-Clause
4-- License : BSD-3-Clause
5-- Maintainer : streamly@composewell.com
5-- Maintainer : streamly@composewell.com
@@ -18,7 +18,7 @@
18{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
18{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
19#endif
19#endif
20
20
21−module Serial.Split (benchmarks) where
21+module Stream.Split (benchmarks) where
22
22
23import Data.Char (ord)
23import Data.Char (ord)
24import Data.Word (Word8)
24import Data.Word (Word8)
benchmark/Streamly/Benchmark/Prelude/Serial/Transformation.hs → benchmark/Streamly/Benchmark/Data/Stream/Transformation.hsrenamed+166−98
@@ -1,5 +1,5 @@
1-- |
1-- |
2−-- Module : Serial.Transformation
2+-- Module : Stream.Transformation
3-- Copyright : (c) 2018 Composewell Technologies
3-- Copyright : (c) 2018 Composewell Technologies
4-- License : BSD-3-Clause
4-- License : BSD-3-Clause
5-- Maintainer : streamly@composewell.com
5-- Maintainer : streamly@composewell.com
@@ -18,29 +18,35 @@
18{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
18{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
19#endif
19#endif
20
20
21−module Serial.Transformation (benchmarks) where
21+module Stream.Transformation (benchmarks) where
22
22
23−import Control.DeepSeq (NFData(..))
24import Control.Monad.IO.Class (MonadIO(..))
23import Control.Monad.IO.Class (MonadIO(..))
25−import Data.Functor.Identity (Identity)
24+
26import System.Random (randomRIO)
25import System.Random (randomRIO)
27
26
28−#ifdef INSPECTION
27+import qualified Streamly.Internal.Data.Fold as FL
29−import Test.Inspection
30−#endif
31
28
29+#ifdef USE_PRELUDE
30+import Streamly.Prelude (fromSerial, MonadAsync)
31+import Streamly.Benchmark.Prelude
32+import Streamly.Internal.Data.Time.Units
33+import qualified Streamly.Benchmark.Prelude as BP
32import qualified Streamly.Prelude as S
34import qualified Streamly.Prelude as S
33−import qualified Streamly.Internal.Data.Stream as Stream
34import qualified Streamly.Internal.Data.Stream.IsStream as Internal
35import qualified Streamly.Internal.Data.Stream.IsStream as Internal
35−import qualified Streamly.Internal.Data.Fold as FL
36import qualified Streamly.Internal.Data.Unfold as Unfold
36import qualified Streamly.Internal.Data.Unfold as Unfold
37+#else
38+import Control.DeepSeq (NFData(..))
39+import Data.Functor.Identity (Identity)
40+import Stream.Common
41+import qualified Streamly.Internal.Data.Stream as Stream
42+import qualified Streamly.Internal.Data.Stream as S
43+import qualified Streamly.Internal.Data.Stream as Internal
37import qualified Prelude
44import qualified Prelude
45+#endif
38
46
39import Gauge
47import Gauge
40−import Streamly.Prelude (SerialT, fromSerial, MonadAsync)
48+import Streamly.Internal.Data.Stream.Serial (SerialT)
41import Streamly.Benchmark.Common
49import Streamly.Benchmark.Common
42−import Streamly.Benchmark.Prelude
43−import Streamly.Internal.Data.Time.Units
44import Prelude hiding (sequence, mapM, fmap)
50import Prelude hiding (sequence, mapM, fmap)
45
51
46-------------------------------------------------------------------------------
52-------------------------------------------------------------------------------
@@ -54,7 +60,7 @@ import Prelude hiding (sequence, mapM, fmap)
54-------------------------------------------------------------------------------
60-------------------------------------------------------------------------------
55-- Traversable Instance
61-- Traversable Instance
56-------------------------------------------------------------------------------
62-------------------------------------------------------------------------------
57−
63+#ifndef USE_PRELUDE
58{-# INLINE traversableTraverse #-}
64{-# INLINE traversableTraverse #-}
59traversableTraverse :: SerialT Identity Int -> IO (SerialT Identity Int)
65traversableTraverse :: SerialT Identity Int -> IO (SerialT Identity Int)
60traversableTraverse = traverse return
66traversableTraverse = traverse return
@@ -89,42 +95,69 @@ o_n_space_traversable value =
89 , benchPureSinkIO value "sequence" traversableSequence
95 , benchPureSinkIO value "sequence" traversableSequence
90 ]
96 ]
91 ]
97 ]
98+#endif
92
99
100+#ifdef USE_PRELUDE
101+{-# INLINE composeNG #-}
102+composeNG ::
103+ (S.IsStream t, Monad m)
104+ => Int
105+ -> (t m Int -> S.SerialT m Int)
106+ -> t m Int
107+ -> m ()
108+composeNG = BP.composeN
109+#else
110+{-# INLINE composeNG #-}
111+composeNG ::
112+ (Monad m)
113+ => Int
114+ -> (SerialT m Int -> SerialT m Int)
115+ -> SerialT m Int
116+ -> m ()
117+composeNG _n = return $ Stream.fold FL.drain
118+#endif
93-------------------------------------------------------------------------------
119-------------------------------------------------------------------------------
94-- maps and scans
120-- maps and scans
95-------------------------------------------------------------------------------
121-------------------------------------------------------------------------------
96
122
123+
124+{-# INLINE scan #-}
125+scan :: MonadIO m => Int -> SerialT m Int -> m ()
126+scan n = composeNG n $ S.scan FL.sum
127+
128+{-# INLINE tap #-}
129+tap :: MonadIO m => Int -> SerialT m Int -> m ()
130+tap n = composeNG n $ S.tap FL.sum
131+
132+#ifdef USE_PRELUDE
97{-# INLINE scanl' #-}
133{-# INLINE scanl' #-}
98scanl' :: MonadIO m => Int -> SerialT m Int -> m ()
134scanl' :: MonadIO m => Int -> SerialT m Int -> m ()
99−scanl' n = composeN n $ S.scanl' (+) 0
135+scanl' n = composeNG n $ S.scanl' (+) 0
100
136
101{-# INLINE scanlM' #-}
137{-# INLINE scanlM' #-}
102scanlM' :: MonadIO m => Int -> SerialT m Int -> m ()
138scanlM' :: MonadIO m => Int -> SerialT m Int -> m ()
103−scanlM' n = composeN n $ S.scanlM' (\b a -> return $ b + a) (return 0)
139+scanlM' n = composeNG n $ S.scanlM' (\b a -> return $ b + a) (return 0)
104
140
105{-# INLINE scanl1' #-}
141{-# INLINE scanl1' #-}
106scanl1' :: MonadIO m => Int -> SerialT m Int -> m ()
142scanl1' :: MonadIO m => Int -> SerialT m Int -> m ()
107−scanl1' n = composeN n $ S.scanl1' (+)
143+scanl1' n = composeNG n $ S.scanl1' (+)
108
144
109{-# INLINE scanl1M' #-}
145{-# INLINE scanl1M' #-}
110scanl1M' :: MonadIO m => Int -> SerialT m Int -> m ()
146scanl1M' :: MonadIO m => Int -> SerialT m Int -> m ()
111−scanl1M' n = composeN n $ S.scanl1M' (\b a -> return $ b + a)
147+scanl1M' n = composeNG n $ S.scanl1M' (\b a -> return $ b + a)
112−
113−{-# INLINE scan #-}
114−scan :: MonadIO m => Int -> SerialT m Int -> m ()
115−scan n = composeN n $ S.scan FL.sum
116
148
117{-# INLINE postscanl' #-}
149{-# INLINE postscanl' #-}
118postscanl' :: MonadIO m => Int -> SerialT m Int -> m ()
150postscanl' :: MonadIO m => Int -> SerialT m Int -> m ()
119−postscanl' n = composeN n $ S.postscanl' (+) 0
151+postscanl' n = composeNG n $ S.postscanl' (+) 0
120
152
121{-# INLINE postscanlM' #-}
153{-# INLINE postscanlM' #-}
122postscanlM' :: MonadIO m => Int -> SerialT m Int -> m ()
154postscanlM' :: MonadIO m => Int -> SerialT m Int -> m ()
123−postscanlM' n = composeN n $ S.postscanlM' (\b a -> return $ b + a) (return 0)
155+postscanlM' n = composeNG n $ S.postscanlM' (\b a -> return $ b + a) (return 0)
156+
124
157
125{-# INLINE postscan #-}
158{-# INLINE postscan #-}
126postscan :: MonadIO m => Int -> SerialT m Int -> m ()
159postscan :: MonadIO m => Int -> SerialT m Int -> m ()
127−postscan n = composeN n $ S.postscan FL.sum
160+postscan n = composeNG n $ S.postscan FL.sum
128
161
129{-# INLINE sequence #-}
162{-# INLINE sequence #-}
130sequence ::
163sequence ::
@@ -134,10 +167,6 @@ sequence ::
134 -> m ()
167 -> m ()
135sequence t = S.drain . t . S.sequence
168sequence t = S.drain . t . S.sequence
136
169
137−{-# INLINE tap #-}
138−tap :: MonadIO m => Int -> SerialT m Int -> m ()
139−tap n = composeN n $ S.tap FL.sum
140−
141{-# INLINE pollCounts #-}
170{-# INLINE pollCounts #-}
142pollCounts :: Int -> SerialT IO Int -> IO ()
171pollCounts :: Int -> SerialT IO Int -> IO ()
143pollCounts n =
172pollCounts n =
@@ -151,26 +180,26 @@ pollCounts n =
151timestamped :: (S.MonadAsync m) => SerialT m Int -> m ()
180timestamped :: (S.MonadAsync m) => SerialT m Int -> m ()
152timestamped = S.drain . Internal.timestamped
181timestamped = S.drain . Internal.timestamped
153
182
183+{-# INLINE trace #-}
184+trace :: MonadAsync m => Int -> SerialT m Int -> m ()
185+trace n = composeNG n $ Internal.trace return
186+#endif
187+
154{-# INLINE foldrS #-}
188{-# INLINE foldrS #-}
155foldrS :: MonadIO m => Int -> SerialT m Int -> m ()
189foldrS :: MonadIO m => Int -> SerialT m Int -> m ()
156−foldrS n = composeN n $ Internal.foldrS S.cons S.nil
190+foldrS n = composeNG n $ Internal.foldrS S.cons S.nil
157
191
158{-# INLINE foldrSMap #-}
192{-# INLINE foldrSMap #-}
159foldrSMap :: MonadIO m => Int -> SerialT m Int -> m ()
193foldrSMap :: MonadIO m => Int -> SerialT m Int -> m ()
160−foldrSMap n = composeN n $ Internal.foldrS (\x xs -> x + 1 `S.cons` xs) S.nil
194+foldrSMap n = composeNG n $ Internal.foldrS (\x xs -> x + 1 `S.cons` xs) S.nil
161
195
162{-# INLINE foldrT #-}
196{-# INLINE foldrT #-}
163foldrT :: MonadIO m => Int -> SerialT m Int -> m ()
197foldrT :: MonadIO m => Int -> SerialT m Int -> m ()
164−foldrT n = composeN n $ Internal.foldrT S.cons S.nil
198+foldrT n = composeNG n $ Internal.foldrT S.cons S.nil
165
199
166{-# INLINE foldrTMap #-}
200{-# INLINE foldrTMap #-}
167foldrTMap :: MonadIO m => Int -> SerialT m Int -> m ()
201foldrTMap :: MonadIO m => Int -> SerialT m Int -> m ()
168−foldrTMap n = composeN n $ Internal.foldrT (\x xs -> x + 1 `S.cons` xs) S.nil
202+foldrTMap n = composeNG n $ Internal.foldrT (\x xs -> x + 1 `S.cons` xs) S.nil
169−
170−
171−{-# INLINE trace #-}
172−trace :: MonadAsync m => Int -> SerialT m Int -> m ()
173−trace n = composeN n $ Internal.trace return
174
203
175o_1_space_mapping :: Int -> [Benchmark]
204o_1_space_mapping :: Int -> [Benchmark]
176o_1_space_mapping value =
205o_1_space_mapping value =
@@ -182,13 +211,13 @@ o_1_space_mapping value =
182 , benchIOSink value "foldrSMap" (foldrSMap 1)
211 , benchIOSink value "foldrSMap" (foldrSMap 1)
183 , benchIOSink value "foldrT" (foldrT 1)
212 , benchIOSink value "foldrT" (foldrT 1)
184 , benchIOSink value "foldrTMap" (foldrTMap 1)
213 , benchIOSink value "foldrTMap" (foldrTMap 1)
185−
214+#ifdef USE_PRELUDE
186 -- Mapping
215 -- Mapping
187 , benchIOSink value "map" (mapN fromSerial 1)
216 , benchIOSink value "map" (mapN fromSerial 1)
188 , bench "sequence" $ nfIO $ randomRIO (1, 1000) >>= \n ->
217 , bench "sequence" $ nfIO $ randomRIO (1, 1000) >>= \n ->
189 sequence fromSerial (sourceUnfoldrAction value n)
218 sequence fromSerial (sourceUnfoldrAction value n)
190 , benchIOSink value "mapM" (mapM fromSerial 1)
219 , benchIOSink value "mapM" (mapM fromSerial 1)
191− , benchIOSink value "tap" (tap 1)
220+
192 , benchIOSink value "pollCounts 1 second" (pollCounts 1)
221 , benchIOSink value "pollCounts 1 second" (pollCounts 1)
193 , benchIOSink value "timestamped" timestamped
222 , benchIOSink value "timestamped" timestamped
194
223
@@ -199,12 +228,15 @@ o_1_space_mapping value =
199 , benchIOSink value "scanl1M'" (scanl1M' 1)
228 , benchIOSink value "scanl1M'" (scanl1M' 1)
200 , benchIOSink value "postscanl'" (postscanl' 1)
229 , benchIOSink value "postscanl'" (postscanl' 1)
201 , benchIOSink value "postscanlM'" (postscanlM' 1)
230 , benchIOSink value "postscanlM'" (postscanlM' 1)
202−
203− , benchIOSink value "scan" (scan 1)
204 , benchIOSink value "postscan" (postscan 1)
231 , benchIOSink value "postscan" (postscan 1)
232+#endif
233+ , benchIOSink value "scan" (scan 1)
234+ , benchIOSink value "tap" (tap 1)
205 ]
235 ]
206 ]
236 ]
207
237
238+
239+#ifdef USE_PRELUDE
208o_1_space_mappingX4 :: Int -> [Benchmark]
240o_1_space_mappingX4 :: Int -> [Benchmark]
209o_1_space_mappingX4 value =
241o_1_space_mappingX4 value =
210 [ bgroup "mappingX4"
242 [ bgroup "mappingX4"
@@ -218,10 +250,10 @@ o_1_space_mappingX4 value =
218 , benchIOSink value "scanl1M'" (scanl1M' 4)
250 , benchIOSink value "scanl1M'" (scanl1M' 4)
219 , benchIOSink value "postscanl'" (postscanl' 4)
251 , benchIOSink value "postscanl'" (postscanl' 4)
220 , benchIOSink value "postscanlM'" (postscanlM' 4)
252 , benchIOSink value "postscanlM'" (postscanlM' 4)
221−
222 ]
253 ]
223 ]
254 ]
224
255
256+
225{-# INLINE sieveScan #-}
257{-# INLINE sieveScan #-}
226sieveScan :: Monad m => SerialT m Int -> SerialT m Int
258sieveScan :: Monad m => SerialT m Int -> SerialT m Int
227sieveScan =
259sieveScan =
@@ -252,85 +284,89 @@ o_1_space_functor value =
252 , benchIOSink value "fmap x 4" (fmapN fromSerial 4)
284 , benchIOSink value "fmap x 4" (fmapN fromSerial 4)
253 ]
285 ]
254 ]
286 ]
255−
287+#else
288+{-# INLINE foldFilterEven #-}
289+foldFilterEven :: MonadIO m => SerialT m Int -> m ()
290+foldFilterEven = Stream.fold FL.drain . Stream.foldFilter (FL.satisfy even)
291+#endif
256-------------------------------------------------------------------------------
292-------------------------------------------------------------------------------
257-- Size reducing transformations (filtering)
293-- Size reducing transformations (filtering)
258-------------------------------------------------------------------------------
294-------------------------------------------------------------------------------
259
295
260{-# INLINE filterEven #-}
296{-# INLINE filterEven #-}
261filterEven :: MonadIO m => Int -> SerialT m Int -> m ()
297filterEven :: MonadIO m => Int -> SerialT m Int -> m ()
262−filterEven n = composeN n $ S.filter even
298+filterEven n = composeNG n $ S.filter even
263
299
264{-# INLINE filterAllOut #-}
300{-# INLINE filterAllOut #-}
265filterAllOut :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
301filterAllOut :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
266−filterAllOut value n = composeN n $ S.filter (> (value + 1))
302+filterAllOut value n = composeNG n $ S.filter (> (value + 1))
267
303
268{-# INLINE filterAllIn #-}
304{-# INLINE filterAllIn #-}
269filterAllIn :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
305filterAllIn :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
270−filterAllIn value n = composeN n $ S.filter (<= (value + 1))
306+filterAllIn value n = composeNG n $ S.filter (<= (value + 1))
271
307
272{-# INLINE filterMEven #-}
308{-# INLINE filterMEven #-}
273filterMEven :: MonadIO m => Int -> SerialT m Int -> m ()
309filterMEven :: MonadIO m => Int -> SerialT m Int -> m ()
274−filterMEven n = composeN n $ S.filterM (return . even)
310+filterMEven n = composeNG n $ S.filterM (return . even)
275
311
276{-# INLINE filterMAllOut #-}
312{-# INLINE filterMAllOut #-}
277filterMAllOut :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
313filterMAllOut :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
278−filterMAllOut value n = composeN n $ S.filterM (\x -> return $ x > (value + 1))
314+filterMAllOut value n = composeNG n $ S.filterM (\x -> return $ x > (value + 1))
279
315
280{-# INLINE filterMAllIn #-}
316{-# INLINE filterMAllIn #-}
281filterMAllIn :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
317filterMAllIn :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
282−filterMAllIn value n = composeN n $ S.filterM (\x -> return $ x <= (value + 1))
318+filterMAllIn value n = composeNG n $ S.filterM (\x -> return $ x <= (value + 1))
283−
284−{-# INLINE foldFilterEven #-}
285−foldFilterEven :: MonadIO m => Int -> SerialT m Int -> m ()
286−foldFilterEven n = composeN n $ Stream.foldFilter (FL.satisfy even)
287
319
288{-# INLINE _takeOne #-}
320{-# INLINE _takeOne #-}
289_takeOne :: MonadIO m => Int -> SerialT m Int -> m ()
321_takeOne :: MonadIO m => Int -> SerialT m Int -> m ()
290−_takeOne n = composeN n $ S.take 1
322+_takeOne n = composeNG n $ S.take 1
291
323
292{-# INLINE takeAll #-}
324{-# INLINE takeAll #-}
293takeAll :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
325takeAll :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
294−takeAll value n = composeN n $ S.take (value + 1)
326+takeAll value n = composeNG n $ S.take (value + 1)
295
327
296{-# INLINE takeWhileTrue #-}
328{-# INLINE takeWhileTrue #-}
297takeWhileTrue :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
329takeWhileTrue :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
298−takeWhileTrue value n = composeN n $ S.takeWhile (<= (value + 1))
330+takeWhileTrue value n = composeNG n $ S.takeWhile (<= (value + 1))
299
331
300{-# INLINE takeWhileMTrue #-}
332{-# INLINE takeWhileMTrue #-}
301takeWhileMTrue :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
333takeWhileMTrue :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
302−takeWhileMTrue value n = composeN n $ S.takeWhileM (return . (<= (value + 1)))
334+takeWhileMTrue value n = composeNG n $ S.takeWhileM (return . (<= (value + 1)))
303
335
336+#ifdef USE_PRELUDE
304{-# INLINE takeInterval #-}
337{-# INLINE takeInterval #-}
305takeInterval :: NanoSecond64 -> Int -> SerialT IO Int -> IO ()
338takeInterval :: NanoSecond64 -> Int -> SerialT IO Int -> IO ()
306takeInterval i n = composeN n (Internal.takeInterval i)
339takeInterval i n = composeN n (Internal.takeInterval i)
307
340
341+
308#ifdef INSPECTION
342#ifdef INSPECTION
309-- inspect $ hasNoType 'takeInterval ''SPEC
343-- inspect $ hasNoType 'takeInterval ''SPEC
310inspect $ hasNoTypeClasses 'takeInterval
344inspect $ hasNoTypeClasses 'takeInterval
311-- inspect $ 'takeInterval `hasNoType` ''D.Step
345-- inspect $ 'takeInterval `hasNoType` ''D.Step
312#endif
346#endif
347+#endif
313
348
314{-# INLINE dropOne #-}
349{-# INLINE dropOne #-}
315dropOne :: MonadIO m => Int -> SerialT m Int -> m ()
350dropOne :: MonadIO m => Int -> SerialT m Int -> m ()
316−dropOne n = composeN n $ S.drop 1
351+dropOne n = composeNG n $ S.drop 1
317
352
318{-# INLINE dropAll #-}
353{-# INLINE dropAll #-}
319dropAll :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
354dropAll :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
320−dropAll value n = composeN n $ S.drop (value + 1)
355+dropAll value n = composeNG n $ S.drop (value + 1)
321
356
322{-# INLINE dropWhileTrue #-}
357{-# INLINE dropWhileTrue #-}
323dropWhileTrue :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
358dropWhileTrue :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
324−dropWhileTrue value n = composeN n $ S.dropWhile (<= (value + 1))
359+dropWhileTrue value n = composeNG n $ S.dropWhile (<= (value + 1))
325
360
326{-# INLINE dropWhileMTrue #-}
361{-# INLINE dropWhileMTrue #-}
327dropWhileMTrue :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
362dropWhileMTrue :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
328−dropWhileMTrue value n = composeN n $ S.dropWhileM (return . (<= (value + 1)))
363+dropWhileMTrue value n = composeNG n $ S.dropWhileM (return . (<= (value + 1)))
329
364
330{-# INLINE dropWhileFalse #-}
365{-# INLINE dropWhileFalse #-}
331dropWhileFalse :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
366dropWhileFalse :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
332−dropWhileFalse value n = composeN n $ S.dropWhile (> (value + 1))
367+dropWhileFalse value n = composeNG n $ S.dropWhile (> (value + 1))
333
368
369+#ifdef USE_PRELUDE
334-- XXX Decide on the time interval
370-- XXX Decide on the time interval
335{-# INLINE _intervalsOfSum #-}
371{-# INLINE _intervalsOfSum #-}
336_intervalsOfSum :: MonadAsync m => Double -> Int -> SerialT m Int -> m ()
372_intervalsOfSum :: MonadAsync m => Double -> Int -> SerialT m Int -> m ()
@@ -344,28 +380,30 @@ dropInterval i n = composeN n (Internal.dropInterval i)
344inspect $ hasNoTypeClasses 'dropInterval
380inspect $ hasNoTypeClasses 'dropInterval
345-- inspect $ 'dropInterval `hasNoType` ''D.Step
381-- inspect $ 'dropInterval `hasNoType` ''D.Step
346#endif
382#endif
383+#endif
347
384
348{-# INLINE findIndices #-}
385{-# INLINE findIndices #-}
349findIndices :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
386findIndices :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
350−findIndices value n = composeN n $ S.findIndices (== (value + 1))
387+findIndices value n = composeNG n $ S.findIndices (== (value + 1))
351
388
352{-# INLINE elemIndices #-}
389{-# INLINE elemIndices #-}
353elemIndices :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
390elemIndices :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
354−elemIndices value n = composeN n $ S.elemIndices (value + 1)
391+elemIndices value n = composeNG n $ S.elemIndices (value + 1)
355
392
356{-# INLINE deleteBy #-}
393{-# INLINE deleteBy #-}
357deleteBy :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
394deleteBy :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
358−deleteBy value n = composeN n $ S.deleteBy (>=) (value + 1)
395+deleteBy value n = composeNG n $ S.deleteBy (>=) (value + 1)
359
396
360-- uniq . uniq == uniq, composeN 2 ~ composeN 1
397-- uniq . uniq == uniq, composeN 2 ~ composeN 1
361{-# INLINE uniq #-}
398{-# INLINE uniq #-}
362uniq :: MonadIO m => Int -> SerialT m Int -> m ()
399uniq :: MonadIO m => Int -> SerialT m Int -> m ()
363−uniq n = composeN n S.uniq
400+uniq n = composeNG n S.uniq
364
401
402+#ifdef USE_PRELUDE
365{-# INLINE mapMaybe #-}
403{-# INLINE mapMaybe #-}
366mapMaybe :: MonadIO m => Int -> SerialT m Int -> m ()
404mapMaybe :: MonadIO m => Int -> SerialT m Int -> m ()
367mapMaybe n =
405mapMaybe n =
368− composeN n $
406+ composeNG n $
369 S.mapMaybe
407 S.mapMaybe
370 (\x ->
408 (\x ->
371 if odd x
409 if odd x
@@ -375,12 +413,13 @@ mapMaybe n =
375{-# INLINE mapMaybeM #-}
413{-# INLINE mapMaybeM #-}
376mapMaybeM :: S.MonadAsync m => Int -> SerialT m Int -> m ()
414mapMaybeM :: S.MonadAsync m => Int -> SerialT m Int -> m ()
377mapMaybeM n =
415mapMaybeM n =
378− composeN n $
416+ composeNG n $
379 S.mapMaybeM
417 S.mapMaybeM
380 (\x ->
418 (\x ->
381 if odd x
419 if odd x
382 then return Nothing
420 then return Nothing
383 else return $ Just x)
421 else return $ Just x)
422+#endif
384
423
385o_1_space_filtering :: Int -> [Benchmark]
424o_1_space_filtering :: Int -> [Benchmark]
386o_1_space_filtering value =
425o_1_space_filtering value =
@@ -392,23 +431,26 @@ o_1_space_filtering value =
392 , benchIOSink value "filterM-even" (filterMEven 1)
431 , benchIOSink value "filterM-even" (filterMEven 1)
393 , benchIOSink value "filterM-all-out" (filterMAllOut value 1)
432 , benchIOSink value "filterM-all-out" (filterMAllOut value 1)
394 , benchIOSink value "filterM-all-in" (filterMAllIn value 1)
433 , benchIOSink value "filterM-all-in" (filterMAllIn value 1)
395−
434+#ifndef USE_PRELUDE
396− , benchIOSink value "foldFilter-even" (foldFilterEven 1)
435+ , benchIOSink value "foldFilter-even" foldFilterEven
436+#endif
397
437
398 -- Trimming
438 -- Trimming
399 , benchIOSink value "take-all" (takeAll value 1)
439 , benchIOSink value "take-all" (takeAll value 1)
400− , benchIOSink
401− value
402− "takeInterval-all"
403− (takeInterval (NanoSecond64 maxBound) 1)
404 , benchIOSink value "takeWhile-true" (takeWhileTrue value 1)
440 , benchIOSink value "takeWhile-true" (takeWhileTrue value 1)
405 -- , benchIOSink value "takeWhileM-true" (_takeWhileMTrue value 1)
441 -- , benchIOSink value "takeWhileM-true" (_takeWhileMTrue value 1)
406 , benchIOSink value "drop-one" (dropOne 1)
442 , benchIOSink value "drop-one" (dropOne 1)
407 , benchIOSink value "drop-all" (dropAll value 1)
443 , benchIOSink value "drop-all" (dropAll value 1)
444+#ifdef USE_PRELUDE
445+ , benchIOSink
446+ value
447+ "takeInterval-all"
448+ (takeInterval (NanoSecond64 maxBound) 1)
408 , benchIOSink
449 , benchIOSink
409 value
450 value
410 "dropInterval-all"
451 "dropInterval-all"
411 (dropInterval (NanoSecond64 maxBound) 1)
452 (dropInterval (NanoSecond64 maxBound) 1)
453+#endif
412 , benchIOSink value "dropWhile-true" (dropWhileTrue value 1)
454 , benchIOSink value "dropWhile-true" (dropWhileTrue value 1)
413 -- , benchIOSink value "dropWhileM-true" (_dropWhileMTrue value 1)
455 -- , benchIOSink value "dropWhileM-true" (_dropWhileMTrue value 1)
414 , benchIOSink
456 , benchIOSink
@@ -418,17 +460,18 @@ o_1_space_filtering value =
418 , benchIOSink value "deleteBy" (deleteBy value 1)
460 , benchIOSink value "deleteBy" (deleteBy value 1)
419
461
420 , benchIOSink value "uniq" (uniq 1)
462 , benchIOSink value "uniq" (uniq 1)
421−
463+#ifdef USE_PRELUDE
422 -- Map and filter
464 -- Map and filter
423 , benchIOSink value "mapMaybe" (mapMaybe 1)
465 , benchIOSink value "mapMaybe" (mapMaybe 1)
424 , benchIOSink value "mapMaybeM" (mapMaybeM 1)
466 , benchIOSink value "mapMaybeM" (mapMaybeM 1)
425−
467+#endif
426 -- Searching (stateful map and filter)
468 -- Searching (stateful map and filter)
427 , benchIOSink value "findIndices" (findIndices value 1)
469 , benchIOSink value "findIndices" (findIndices value 1)
428 , benchIOSink value "elemIndices" (elemIndices value 1)
470 , benchIOSink value "elemIndices" (elemIndices value 1)
429 ]
471 ]
430 ]
472 ]
431
473
474+
432o_1_space_filteringX4 :: Int -> [Benchmark]
475o_1_space_filteringX4 :: Int -> [Benchmark]
433o_1_space_filteringX4 value =
476o_1_space_filteringX4 value =
434 [ bgroup "filteringX4"
477 [ bgroup "filteringX4"
@@ -440,7 +483,7 @@ o_1_space_filteringX4 value =
440 , benchIOSink value "filterM-all-out" (filterMAllOut value 4)
483 , benchIOSink value "filterM-all-out" (filterMAllOut value 4)
441 , benchIOSink value "filterM-all-in" (filterMAllIn value 4)
484 , benchIOSink value "filterM-all-in" (filterMAllIn value 4)
442
485
443− , benchIOSink value "foldFilter-even" (foldFilterEven 4)
486+ --, benchIOSink value "foldFilter-even" (foldFilterEven 4)
444
487
445 -- trimming
488 -- trimming
446 , benchIOSink value "take-all" (takeAll value 4)
489 , benchIOSink value "take-all" (takeAll value 4)
@@ -458,10 +501,11 @@ o_1_space_filteringX4 value =
458
501
459 , benchIOSink value "uniq" (uniq 4)
502 , benchIOSink value "uniq" (uniq 4)
460
503
504+#ifdef USE_PRELUDE
461 -- map and filter
505 -- map and filter
462 , benchIOSink value "mapMaybe" (mapMaybe 4)
506 , benchIOSink value "mapMaybe" (mapMaybe 4)
463 , benchIOSink value "mapMaybeM" (mapMaybeM 4)
507 , benchIOSink value "mapMaybeM" (mapMaybeM 4)
464−
508+#endif
465 -- searching
509 -- searching
466 , benchIOSink value "findIndices" (findIndices value 4)
510 , benchIOSink value "findIndices" (findIndices value 4)
467 , benchIOSink value "elemIndices" (elemIndices value 4)
511 , benchIOSink value "elemIndices" (elemIndices value 4)
@@ -471,28 +515,29 @@ o_1_space_filteringX4 value =
471-------------------------------------------------------------------------------
515-------------------------------------------------------------------------------
472-- Size increasing transformations (insertions)
516-- Size increasing transformations (insertions)
473-------------------------------------------------------------------------------
517-------------------------------------------------------------------------------
474−
518+#ifdef USE_PRELUDE
475{-# INLINE intersperse #-}
519{-# INLINE intersperse #-}
476intersperse :: S.MonadAsync m => Int -> Int -> SerialT m Int -> m ()
520intersperse :: S.MonadAsync m => Int -> Int -> SerialT m Int -> m ()
477−intersperse value n = composeN n $ S.intersperse (value + 1)
521+intersperse value n = composeNG n $ S.intersperse (value + 1)
478
522
479{-# INLINE intersperseM #-}
523{-# INLINE intersperseM #-}
480intersperseM :: S.MonadAsync m => Int -> Int -> SerialT m Int -> m ()
524intersperseM :: S.MonadAsync m => Int -> Int -> SerialT m Int -> m ()
481−intersperseM value n = composeN n $ S.intersperseM (return $ value + 1)
525+intersperseM value n = composeNG n $ S.intersperseM (return $ value + 1)
482−
483−{-# INLINE insertBy #-}
484−insertBy :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
485−insertBy value n = composeN n $ S.insertBy compare (value + 1)
486
526
487{-# INLINE interposeSuffix #-}
527{-# INLINE interposeSuffix #-}
488interposeSuffix :: S.MonadAsync m => Int -> Int -> SerialT m Int -> m ()
528interposeSuffix :: S.MonadAsync m => Int -> Int -> SerialT m Int -> m ()
489interposeSuffix value n =
529interposeSuffix value n =
490− composeN n $ Internal.interposeSuffix (value + 1) Unfold.identity
530+ composeNG n $ Internal.interposeSuffix (value + 1) Unfold.identity
491
531
492{-# INLINE intercalateSuffix #-}
532{-# INLINE intercalateSuffix #-}
493intercalateSuffix :: S.MonadAsync m => Int -> Int -> SerialT m Int -> m ()
533intercalateSuffix :: S.MonadAsync m => Int -> Int -> SerialT m Int -> m ()
494intercalateSuffix value n =
534intercalateSuffix value n =
495− composeN n $ Internal.intercalateSuffix Unfold.identity (value + 1)
535+ composeNG n $ Internal.intercalateSuffix Unfold.identity (value + 1)
536+
537+{-# INLINE insertBy #-}
538+insertBy :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
539+insertBy value n = composeNG n $ S.insertBy compare (value + 1)
540+
496
541
497o_1_space_inserting :: Int -> [Benchmark]
542o_1_space_inserting :: Int -> [Benchmark]
498o_1_space_inserting value =
543o_1_space_inserting value =
@@ -509,14 +554,14 @@ o_1_space_insertingX4 :: Int -> [Benchmark]
509o_1_space_insertingX4 value =
554o_1_space_insertingX4 value =
510 [ bgroup "insertingX4"
555 [ bgroup "insertingX4"
511 [ benchIOSink value "intersperse" (intersperse value 4)
556 [ benchIOSink value "intersperse" (intersperse value 4)
512− , benchIOSink value "insertBy" (insertBy value 4)
557+ -- , benchIOSink value "insertBy" (insertBy value 4)
513 ]
558 ]
514 ]
559 ]
515−
560+#endif
516-------------------------------------------------------------------------------
561-------------------------------------------------------------------------------
517-- Indexing
562-- Indexing
518-------------------------------------------------------------------------------
563-------------------------------------------------------------------------------
519−
564+#ifdef USE_PRELUDE
520{-# INLINE indexed #-}
565{-# INLINE indexed #-}
521indexed :: MonadIO m => Int -> SerialT m Int -> m ()
566indexed :: MonadIO m => Int -> SerialT m Int -> m ()
522indexed n = composeN n (S.map snd . S.indexed)
567indexed n = composeN n (S.map snd . S.indexed)
@@ -541,6 +586,24 @@ o_1_space_indexingX4 value =
541 ]
586 ]
542 ]
587 ]
543
588
589+#else
590+{-# INLINE indexed #-}
591+indexed :: MonadIO m => SerialT m Int -> m ()
592+indexed = Stream.fold FL.drain . Prelude.fmap snd . Stream.indexed
593+
594+{-# INLINE indexedR #-}
595+indexedR :: MonadIO m => Int -> SerialT m Int -> m ()
596+indexedR value = Stream.fold FL.drain . (Prelude.fmap snd . Stream.indexedR value)
597+
598+o_1_space_indexing :: Int -> [Benchmark]
599+o_1_space_indexing value =
600+ [ bgroup "indexing"
601+ [ benchIOSink value "indexed" indexed
602+ , benchIOSink value "indexedR" (indexedR value)
603+ ]
604+ ]
605+#endif
606+
544-------------------------------------------------------------------------------
607-------------------------------------------------------------------------------
545-- Main
608-- Main
546-------------------------------------------------------------------------------
609-------------------------------------------------------------------------------
@@ -551,18 +614,23 @@ o_1_space_indexingX4 value =
551benchmarks :: String -> Int -> [Benchmark]
614benchmarks :: String -> Int -> [Benchmark]
552benchmarks moduleName size =
615benchmarks moduleName size =
553 [ bgroup (o_1_space_prefix moduleName) $ Prelude.concat
616 [ bgroup (o_1_space_prefix moduleName) $ Prelude.concat
554− [ o_1_space_functor size
555− , o_1_space_mapping size
617+ [ o_1_space_mapping size
556− , o_1_space_mappingX4 size
618+ , o_1_space_indexing size
557 , o_1_space_filtering size
619 , o_1_space_filtering size
558 , o_1_space_filteringX4 size
620 , o_1_space_filteringX4 size
621+#ifdef USE_PRELUDE
622+ , o_1_space_functor size
623+ , o_1_space_mappingX4 size
559 , o_1_space_inserting size
624 , o_1_space_inserting size
560 , o_1_space_insertingX4 size
625 , o_1_space_insertingX4 size
561− , o_1_space_indexing size
562 , o_1_space_indexingX4 size
626 , o_1_space_indexingX4 size
627+#endif
563 ]
628 ]
629+
564− , bgroup (o_n_space_prefix moduleName) $ Prelude.concat
630+ , bgroup (o_n_space_prefix moduleName) $
631+#ifdef USE_PRELUDE
632+ o_n_space_mapping size
633+#else
565− [ o_n_space_traversable size
634+ o_n_space_traversable size
566− , o_n_space_mapping size
635+#endif
567− ]
568 ]
636 ]
benchmark/bench-runner/Main.hs+9−9
@@ -35,22 +35,22 @@ rtsOpts exeName benchName0 = unwords [general, exeSpecific, benchSpecific]
35 `isPrefixOf` benchName = "-K2M -M256M"
35 `isPrefixOf` benchName = "-K2M -M256M"
36 | "Prelude.Rate/o-1-space." `isPrefixOf` benchName = "-K128K"
36 | "Prelude.Rate/o-1-space." `isPrefixOf` benchName = "-K128K"
37 | "Prelude.Rate/o-1-space.asyncly." `isPrefixOf` benchName = "-K128K"
37 | "Prelude.Rate/o-1-space.asyncly." `isPrefixOf` benchName = "-K128K"
38− | "Prelude.Serial/o-1-space.mixed.sum-product-fold" == benchName =
38+ | "Data.Stream/o-1-space.mixed.sum-product-fold" == benchName =
39 "-K64M"
39 "-K64M"
40− | "Prelude.Serial/o-n-heap.grouping.classifySessionsOf"
40+ | "Data.Stream/o-n-heap.grouping.classifySessionsOf"
41 `isPrefixOf` benchName = "-K1M -M32M"
41 `isPrefixOf` benchName = "-K1M -M32M"
42− | "Prelude.Serial/o-n-heap.Functor." `isPrefixOf` benchName =
42+ | "Data.Stream/o-n-heap.Functor." `isPrefixOf` benchName =
43 "-K4M -M32M"
43 "-K4M -M32M"
44− | "Prelude.Serial/o-n-heap.transformer." `isPrefixOf` benchName =
44+ | "Data.Stream/o-n-heap.transformer." `isPrefixOf` benchName =
45 "-K8M -M64M"
45 "-K8M -M64M"
46− | "Prelude.Serial/o-n-space.Functor." `isPrefixOf` benchName =
46+ | "Data.Stream/o-n-space.Functor." `isPrefixOf` benchName =
47 "-K4M -M64M"
47 "-K4M -M64M"
48− | "Prelude.Serial/o-n-space.Applicative." `isPrefixOf` benchName =
48+ | "Data.Stream/o-n-space.Applicative." `isPrefixOf` benchName =
49 "-K8M -M128M"
49 "-K8M -M128M"
50− | "Prelude.Serial/o-n-space.Monad." `isPrefixOf` benchName =
50+ | "Data.Stream/o-n-space.Monad." `isPrefixOf` benchName =
51 "-K8M -M64M"
51 "-K8M -M64M"
52− | "Prelude.Serial/o-n-space.grouping." `isPrefixOf` benchName = ""
52+ | "Data.Stream/o-n-space.grouping." `isPrefixOf` benchName = ""
53− | "Prelude.Serial/o-n-space." `isPrefixOf` benchName = "-K4M"
53+ | "Data.Stream/o-n-space." `isPrefixOf` benchName = "-K4M"
54 | "Prelude.WSerial/o-n-space." `isPrefixOf` benchName = "-K4M"
54 | "Prelude.WSerial/o-n-space." `isPrefixOf` benchName = "-K4M"
55 | "Prelude.Async/o-n-space.monad-outer-product." `isPrefixOf` benchName =
55 | "Prelude.Async/o-n-space.monad-outer-product." `isPrefixOf` benchName =
56 "-K4M"
56 "-K4M"
benchmark/streamly-benchmarks.cabal+38−25
@@ -64,6 +64,10 @@ flag bench-core
64 manual: True
64 manual: True
65 default: False
65 default: False
66
66
67+flag use-prelude
68+ description: Use Streamly.Prelude instead of Streamly.Data.Stream for serial benchmarks
69+ manual: True
70+ default: False
67-------------------------------------------------------------------------------
71-------------------------------------------------------------------------------
68-- Common stanzas
72-- Common stanzas
69-------------------------------------------------------------------------------
73-------------------------------------------------------------------------------
@@ -71,6 +75,9 @@ flag bench-core
71common compile-options
75common compile-options
72 default-language: Haskell2010
76 default-language: Haskell2010
73
77
78+ if flag(use-prelude)
79+ cpp-options: -DUSE_PRELUDE
80+
74 if flag(dev)
81 if flag(dev)
75 cpp-options: -DDEVBUILD
82 cpp-options: -DDEVBUILD
76
83
@@ -201,31 +208,6 @@ common bench-options-threaded
201-- Serial Streams
208-- Serial Streams
202-------------------------------------------------------------------------------
209-------------------------------------------------------------------------------
203
210
204−benchmark Prelude.Serial
205− import: bench-options
206− type: exitcode-stdio-1.0
207− hs-source-dirs: Streamly/Benchmark/Prelude
208− main-is: Serial.hs
209− other-modules:
210− Serial.Generation
211− , Serial.Elimination
212− , Serial.Transformation
213− , Serial.NestedStream
214− , Serial.NestedFold
215− , Serial.Split
216− , Serial.Exceptions
217− , Serial.Lift
218− if flag(bench-core) || impl(ghcjs)
219− buildable: False
220− else
221− buildable: True
222− if flag(limit-build-mem)
223− if flag(dev)
224− ghc-options: +RTS -M3500M -RTS
225− else
226− ghc-options: +RTS -M2500M -RTS
227−
228−
229benchmark Prelude.WSerial
211benchmark Prelude.WSerial
230 import: bench-options
212 import: bench-options
231 type: exitcode-stdio-1.0
213 type: exitcode-stdio-1.0
@@ -405,6 +387,37 @@ benchmark Data.Parser
405-------------------------------------------------------------------------------
387-------------------------------------------------------------------------------
406-- Raw Streams
388-- Raw Streams
407-------------------------------------------------------------------------------
389-------------------------------------------------------------------------------
390+benchmark Data.Stream
391+ import: bench-options
392+ type: exitcode-stdio-1.0
393+ hs-source-dirs: Streamly/Benchmark/Data
394+ main-is: Stream.hs
395+ other-modules:
396+ Stream.Eliminate
397+ Stream.Exceptions
398+ Stream.Generate
399+ Stream.Lift
400+ Stream.Transformation
401+ if flag(use-prelude)
402+ other-modules:
403+ Stream.NestedFold
404+ Stream.NestedStream
405+ Stream.Split
406+ else
407+ other-modules:
408+ Stream.Common
409+ Stream.Reduce
410+
411+ if flag(bench-core) || impl(ghcjs)
412+ buildable: False
413+ else
414+ buildable: True
415+ build-depends: exceptions >= 0.8 && < 0.11
416+ if flag(limit-build-mem)
417+ if flag(dev)
418+ ghc-options: +RTS -M3500M -RTS
419+ else
420+ ghc-options: +RTS -M2000M -RTS
408
421
409benchmark Data.Stream.StreamD
422benchmark Data.Stream.StreamD
410 import: bench-options
423 import: bench-options
hie.yaml+2−18
@@ -30,6 +30,8 @@ cradle:
30 component: "bench:Data.Stream.StreamD"
30 component: "bench:Data.Stream.StreamD"
31 - path: "./benchmark/Streamly/Benchmark/Data/Stream/StreamK.hs"
31 - path: "./benchmark/Streamly/Benchmark/Data/Stream/StreamK.hs"
32 component: "bench:Data.Stream.StreamK"
32 component: "bench:Data.Stream.StreamK"
33+ - path: "./benchmark/Streamly/Benchmark/Data/Stream/*.hs"
34+ component: "bench:Data.Stream"
33 - path: "./benchmark/Streamly/Benchmark/Data/Unfold.hs"
35 - path: "./benchmark/Streamly/Benchmark/Data/Unfold.hs"
34 component: "bench:Data.Unfold"
36 component: "bench:Data.Unfold"
35 - path: "./benchmark/Streamly/Benchmark/FileSystem/Handle/Read.hs"
37 - path: "./benchmark/Streamly/Benchmark/FileSystem/Handle/Read.hs"
@@ -44,24 +46,6 @@ cradle:
44 component: "bench:Prelude.Merge"
46 component: "bench:Prelude.Merge"
45 - path: "./benchmark/Streamly/Benchmark/Prelude/Parallel.hs"
47 - path: "./benchmark/Streamly/Benchmark/Prelude/Parallel.hs"
46 component: "bench:Prelude.Parallel"
48 component: "bench:Prelude.Parallel"
47− - path: "./benchmark/Streamly/Benchmark/Prelude/Serial.hs"
48− component: "bench:Prelude.Serial"
49− - path: "./benchmark/Streamly/Benchmark/Prelude/Serial/Elimination.hs"
50− component: "bench:Prelude.Serial"
51− - path: "./benchmark/Streamly/Benchmark/Prelude/Serial/Exceptions.hs"
52− component: "bench:Prelude.Serial"
53− - path: "./benchmark/Streamly/Benchmark/Prelude/Serial/Generation.hs"
54− component: "bench:Prelude.Serial"
55− - path: "./benchmark/Streamly/Benchmark/Prelude/Serial/NestedStream.hs"
56− component: "bench:Prelude.Serial"
57− - path: "./benchmark/Streamly/Benchmark/Prelude/Serial/Split.hs"
58− component: "bench:Prelude.Serial"
59− - path: "./benchmark/Streamly/Benchmark/Prelude/Serial/Transformation.hs"
60− component: "bench:Prelude.Serial"
61− - path: "./benchmark/Streamly/Benchmark/Prelude/Serial/NestedFold.hs"
62− component: "bench:Prelude.Serial"
63− - path: "./benchmark/Streamly/Benchmark/Prelude/Serial/Lift.hs"
64− component: "bench:Prelude.Serial"
65 - path: "./benchmark/Streamly/Benchmark/Prelude/WSerial.hs"
49 - path: "./benchmark/Streamly/Benchmark/Prelude/WSerial.hs"
66 component: "bench:Prelude.WSerial"
50 component: "bench:Prelude.WSerial"
67 - path: "./benchmark/Streamly/Benchmark/Prelude/ZipSerial.hs"
51 - path: "./benchmark/Streamly/Benchmark/Prelude/ZipSerial.hs"
streamly.cabal−1
@@ -65,7 +65,6 @@ extra-source-files:
65 benchmark/Streamly/Benchmark/FileSystem/*.hs
65 benchmark/Streamly/Benchmark/FileSystem/*.hs
66 benchmark/Streamly/Benchmark/FileSystem/Handle/*.hs
66 benchmark/Streamly/Benchmark/FileSystem/Handle/*.hs
67 benchmark/Streamly/Benchmark/Prelude/*.hs
67 benchmark/Streamly/Benchmark/Prelude/*.hs
68− benchmark/Streamly/Benchmark/Prelude/Serial/*.hs
69 benchmark/Streamly/Benchmark/Unicode/*.hs
68 benchmark/Streamly/Benchmark/Unicode/*.hs
70 benchmark/lib/Streamly/Benchmark/*.hs
69 benchmark/lib/Streamly/Benchmark/*.hs
71 benchmark/lib/Streamly/Benchmark/Common/*.hs
70 benchmark/lib/Streamly/Benchmark/Common/*.hs
targets/Targets.hs+2−2
@@ -25,9 +25,9 @@ targets =
25 )
25 )
26
26
27 -- Streams
27 -- Streams
28− , ("Prelude.Serial", ["serial_wserial_cmp"])
28+ , ("Data.Stream", ["serial_wserial_cmp"])
29 , ("Prelude.WSerial", ["serial_wserial_cmp"])
29 , ("Prelude.WSerial", ["serial_wserial_cmp"])
30− , ("Prelude.Serial",
30+ , ("Data.Stream",
31 [ "prelude_serial_grp"
31 [ "prelude_serial_grp"
32 , "infinite_grp"
32 , "infinite_grp"
33 , "serial_wserial_cmp"
33 , "serial_wserial_cmp"