on master help sign in
Merge pull request #1751
commitf5ef71303ee2cdafa3ed34ed4d235a39c03f7ef2 authorHarendra Kumar <harendra@composewell.com> dateSat 6 Aug 2022, 23:14 (4 years ago) parentd2aaef0bfb1624
17 files changed+1143−481
.github/workflows/regression-check.yml+1−1 .hlint.yaml+7−6 benchmark/Streamly/Benchmark/Prelude/Serial.hs → benchmark/Streamly/Benchmark/Data/Stream.hs+14−10 benchmark/Streamly/Benchmark/Data/Stream/Common.hs+472 benchmark/Streamly/Benchmark/Prelude/Serial/Elimination.hs → benchmark/Streamly/Benchmark/Data/Stream/Eliminate.hs+87−54 benchmark/Streamly/Benchmark/Prelude/Serial/Exceptions.hs → benchmark/Streamly/Benchmark/Data/Stream/Exceptions.hs+72−54 benchmark/Streamly/Benchmark/Prelude/Serial/NestedStream.hs → benchmark/Streamly/Benchmark/Data/Stream/Expand.hs+86−70 benchmark/Streamly/Benchmark/Prelude/Serial/Generation.hs → benchmark/Streamly/Benchmark/Data/Stream/Generate.hs+72−34 benchmark/Streamly/Benchmark/Prelude/Serial/Lift.hs → benchmark/Streamly/Benchmark/Data/Stream/Lift.hs+42−22 benchmark/Streamly/Benchmark/Prelude/Serial/NestedFold.hs → benchmark/Streamly/Benchmark/Data/Stream/Reduce.hs+137−86 benchmark/Streamly/Benchmark/Prelude/Serial/Split.hs → benchmark/Streamly/Benchmark/Data/Stream/Split.hs+2−2 benchmark/Streamly/Benchmark/Prelude/Serial/Transformation.hs → benchmark/Streamly/Benchmark/Data/Stream/Transform.hs+108−100 benchmark/bench-runner/Main.hs+9−9 benchmark/streamly-benchmarks.cabal+22−12 hie.yaml+10−18 streamly.cabal−1 targets/Targets.hs+2−2
.github/workflows/regression-check.yml+1−1
@@ -29,11 +29,11 @@ jobs:
2929 Data.Stream.StreamDK
3030 Data.Stream.StreamK:6
3131 Data.Unfold
32+ Data.Stream
3233 FileSystem.Handle
3334 Prelude.Ahead
3435 Prelude.Async:12
3536 Prelude.Parallel
36− Prelude.Serial
3737 Prelude.WAsync:6
3838 Prelude.WSerial
3939 Prelude.ZipAsync
.hlint.yaml+7−6
@@ -26,12 +26,13 @@
2626- ignore: {name: "Use fmap"}
2727
2828# Warnings ignored in specific places
29−- ignore: {name: "Use ++", within: Serial.Transformation}
30−- ignore: {name: "Use mapM", within: Serial.Transformation}
31−- ignore: {name: "Use traverse", within: Serial.Transformation}
32−
33−- ignore: {name: "Redundant <*", within: Serial.NestedStream}
34−- ignore: {name: "Use ++", within: Serial.NestedStream}
29+- ignore: {name: "Use ++", within: Stream.Transform}
30+- ignore: {name: "Use mapM", within: Stream.Transform}
31+- ignore: {name: "Use traverse", within: Stream.Transform}
32+- ignore: {name: "Redundant <*", within: Stream.Expand}
33+- ignore: {name: "Use ++", within: Stream.Reduce}
34+- ignore: {name: "Use ++", within: Stream.Split}
35+- ignore: {name: "Redundant bracket", within: Stream.Split}
3536- ignore: {name: "Use isDigit", within: Streamly.Internal.Unicode.Char.Parser}
3637
3738# Specify additional command line arguments
benchmark/Streamly/Benchmark/Prelude/Serial.hs → benchmark/Streamly/Benchmark/Data/Stream.hsrenamed+14−10
@@ -1,5 +1,5 @@
11-- |
2−-- Module : Serial
2+-- Module : Data.Stream
33-- Copyright : (c) 2018 Composewell Technologies
44-- License : BSD-3-Clause
55-- Maintainer : streamly@composewell.com
@@ -13,19 +13,21 @@ module Main (main) where
1313
1414import Streamly.Benchmark.Common.Handle (mkHandleBenchEnv)
1515
16−import qualified Serial.Elimination as Elimination
17−import qualified Serial.Exceptions as Exceptions
18−import qualified Serial.Generation as Generation
19−import qualified Serial.NestedStream as NestedStream
20−import qualified Serial.Split as Split
21−import qualified Serial.Transformation as Transformation
22−import qualified Serial.NestedFold as NestedFold
23−import qualified Serial.Lift as Lift
16+import qualified Stream.Eliminate as Elimination
17+import qualified Stream.Exceptions as Exceptions
18+import qualified Stream.Expand as NestedStream
19+import qualified Stream.Generate as Generation
20+import qualified Stream.Lift as Lift
21+import qualified Stream.Reduce as NestedFold
22+#ifdef USE_PRELUDE
23+import qualified Stream.Split as Split
24+#endif
25+import qualified Stream.Transform as Transformation
2426
2527import Streamly.Benchmark.Common
2628
2729moduleName :: String
28−moduleName = "Prelude.Serial"
30+moduleName = "Data.Stream"
2931
3032-------------------------------------------------------------------------------
3133-- Main
@@ -45,7 +47,9 @@ main = do
4547 [ Generation.benchmarks moduleName size
4648 , Elimination.benchmarks moduleName size
4749 , Exceptions.benchmarks moduleName env size
50+#ifdef USE_PRELUDE
4851 , Split.benchmarks moduleName env
52+#endif
4953 , Transformation.benchmarks moduleName size
5054 , NestedFold.benchmarks moduleName size
5155 , Lift.benchmarks moduleName size
benchmark/Streamly/Benchmark/Data/Stream/Common.hsnew file+472
@@ -0,0 +1,472 @@
1+{-# LANGUAGE ConstraintKinds #-}
2+{-# LANGUAGE CPP #-}
3+{-# LANGUAGE FlexibleContexts #-}
4+{-# LANGUAGE ScopedTypeVariables #-}
5+
6+-- |
7+-- Module : Stream.Common
8+-- Copyright : (c) 2018 Composewell Technologies
9+-- License : BSD-3-Clause
10+-- Maintainer : streamly@composewell.com
11+
12+module Stream.Common
13+ ( MonadAsync
14+
15+ -- Generation
16+ , enumerateFromTo
17+ , replicate
18+ , unfoldrM
19+ , fromListM
20+
21+ , append
22+ , append2
23+
24+ -- Elimination
25+ , drain
26+ , foldl'
27+ , scanl'
28+
29+ -- Benchmark stream generation
30+ , sourceUnfoldr
31+ , sourceUnfoldrM
32+ , sourceUnfoldrAction
33+ , sourceConcatMapId
34+ , sourceFromFoldable
35+ , sourceFromFoldableM
36+
37+ -- Benchmark stream elimination
38+ , benchIOSink
39+ , benchIOSrc
40+
41+ -- Benchmarking functions
42+ , concatStreamsWith
43+ , concatPairsWith
44+ , apDiscardFst
45+ , apDiscardSnd
46+ , apLiftA2
47+ , toNullAp
48+ , monadThen
49+ , toNullM
50+ , toNullM3
51+ , filterAllOutM
52+ , filterAllInM
53+ , filterSome
54+ , breakAfterSome
55+ , toListM
56+ , toListSome
57+ , composeN
58+ , mapN
59+ , mapM
60+ , transformMapM
61+ , transformComposeMapM
62+ , transformTeeMapM
63+ , transformZipMapM
64+ )
65+where
66+
67+import Control.Applicative (liftA2)
68+import Control.Exception (try)
69+import GHC.Exception (ErrorCall)
70+import Streamly.Internal.Data.Stream (Stream)
71+import System.Random (randomRIO)
72+
73+import qualified Streamly.Internal.Data.Fold as Fold
74+import qualified Streamly.Internal.Data.Pipe as Pipe
75+
76+#ifdef USE_PRELUDE
77+import Streamly.Prelude (foldl', scanl')
78+import qualified Streamly.Internal.Data.Stream.IsStream as Stream
79+import qualified Streamly.Prelude as Stream
80+import Streamly.Benchmark.Prelude
81+ ( composeN, sourceUnfoldr, sourceUnfoldr, sourceFromFoldable
82+ , sourceFromFoldableM, sourceUnfoldrAction, sourceConcatMapId, benchIOSink
83+ , concatStreamsWith, concatPairsWith
84+ )
85+#else
86+import Control.DeepSeq (NFData)
87+import Streamly.Internal.Data.Stream (unfold)
88+import qualified Streamly.Internal.Data.Stream as Stream
89+import qualified Streamly.Internal.Data.Unfold as Unfold
90+#endif
91+
92+import Gauge
93+import Prelude hiding (mapM, replicate)
94+
95+#ifdef USE_PRELUDE
96+type MonadAsync m = Stream.MonadAsync m
97+#else
98+type MonadAsync = Monad
99+#endif
100+
101+{-# INLINE append #-}
102+append :: Stream m a -> Stream m a -> Stream m a
103+#ifdef USE_PRELUDE
104+append = Stream.serial
105+#else
106+append = Stream.append
107+#endif
108+
109+{-# INLINE append2 #-}
110+append2 :: Monad m => Stream m a -> Stream m a -> Stream m a
111+#ifdef USE_PRELUDE
112+append2 = Stream.append
113+#else
114+append2 = Stream.append2
115+#endif
116+
117+{-# INLINE drain #-}
118+drain :: Monad m => Stream m a -> m ()
119+drain = Stream.fold Fold.drain
120+
121+{-# INLINE enumerateFromTo #-}
122+enumerateFromTo :: Monad m => Int -> Int -> Stream m Int
123+#ifdef USE_PRELUDE
124+enumerateFromTo = Stream.enumerateFromTo
125+#else
126+enumerateFromTo from to = Stream.unfold Unfold.enumerateFromTo (from, to)
127+#endif
128+
129+{-# INLINE replicate #-}
130+replicate :: Monad m => Int -> a -> Stream m a
131+#ifdef USE_PRELUDE
132+replicate = Stream.replicate
133+#else
134+replicate n = Stream.unfold (Unfold.replicateM n) . return
135+#endif
136+
137+{-# INLINE unfoldrM #-}
138+unfoldrM :: MonadAsync m => (b -> m (Maybe (a, b))) -> b -> Stream m a
139+#ifdef USE_PRELUDE
140+unfoldrM = Stream.unfoldrM
141+#else
142+unfoldrM step = Stream.unfold (Unfold.unfoldrM step)
143+#endif
144+
145+{-# INLINE fromListM #-}
146+fromListM :: MonadAsync m => [m a] -> Stream m a
147+#ifdef USE_PRELUDE
148+fromListM = Stream.fromListM
149+#else
150+fromListM = Stream.unfold Unfold.fromListM
151+#endif
152+
153+{-# INLINE sourceUnfoldrM #-}
154+sourceUnfoldrM :: MonadAsync m => Int -> Int -> Stream m Int
155+sourceUnfoldrM count start = unfoldrM step start
156+
157+ where
158+
159+ step cnt =
160+ if cnt > start + count
161+ then return Nothing
162+ else return (Just (cnt, cnt + 1))
163+
164+#ifndef USE_PRELUDE
165+{-# INLINE sourceUnfoldr #-}
166+sourceUnfoldr :: Monad m => Int -> Int -> Stream m Int
167+sourceUnfoldr count start = unfold (Unfold.unfoldr step) start
168+
169+ where
170+
171+ step cnt =
172+ if cnt > start + count
173+ then Nothing
174+ else Just (cnt, cnt + 1)
175+
176+{-# INLINE sourceUnfoldrAction #-}
177+sourceUnfoldrAction :: (Monad m1, Monad m) => Int -> Int -> Stream m (m1 Int)
178+sourceUnfoldrAction value n = unfold (Unfold.unfoldr step) n
179+
180+ where
181+
182+ step cnt =
183+ if cnt > n + value
184+ then Nothing
185+ else Just (return cnt, cnt + 1)
186+
187+{-# INLINE sourceFromFoldable #-}
188+sourceFromFoldable :: Int -> Int -> Stream m Int
189+sourceFromFoldable value n = Stream.fromFoldable [n..n+value]
190+
191+{-# INLINE sourceFromFoldableM #-}
192+sourceFromFoldableM :: Monad m => Int -> Int -> Stream m Int
193+sourceFromFoldableM value n = Stream.fromFoldableM (fmap return [n..n+value])
194+
195+{-# INLINE benchIOSink #-}
196+benchIOSink
197+ :: (NFData b)
198+ => Int -> String -> (Stream IO Int -> IO b) -> Benchmark
199+benchIOSink value name f =
200+ bench name $ nfIO $ randomRIO (1,1) >>= f . sourceUnfoldrM value
201+#endif
202+
203+-- | Takes a source, and uses it with a default drain/fold method.
204+{-# INLINE benchIOSrc #-}
205+benchIOSrc
206+ :: String
207+ -> (Int -> Stream IO a)
208+ -> Benchmark
209+benchIOSrc name f =
210+ bench name $ nfIO $ randomRIO (1,1) >>= drain . f
211+
212+#ifndef USE_PRELUDE
213+{-# INLINE concatStreamsWith #-}
214+concatStreamsWith
215+ :: (Stream IO Int -> Stream IO Int -> Stream IO Int)
216+ -> Int
217+ -> Int
218+ -> Int
219+ -> IO ()
220+concatStreamsWith op outer inner n =
221+ drain $ Stream.concatMapWith op
222+ (sourceUnfoldrM inner)
223+ (sourceUnfoldrM outer n)
224+
225+{-# INLINE concatPairsWith #-}
226+concatPairsWith
227+ :: (Stream IO Int -> Stream IO Int -> Stream IO Int)
228+ -> Int
229+ -> Int
230+ -> Int
231+ -> IO ()
232+concatPairsWith op outer inner n =
233+ drain $ Stream.concatPairsWith op
234+ (sourceUnfoldrM inner)
235+ (sourceUnfoldrM outer n)
236+
237+{-# INLINE sourceConcatMapId #-}
238+sourceConcatMapId :: (Monad m)
239+ => Int -> Int -> Stream m (Stream m Int)
240+sourceConcatMapId value n =
241+ Stream.fromFoldable $ fmap (Stream.fromEffect . return) [n..n+value]
242+#endif
243+
244+{-# INLINE apDiscardFst #-}
245+apDiscardFst :: MonadAsync m =>
246+ Int -> Int -> m ()
247+apDiscardFst linearCount start = drain $
248+ sourceUnfoldrM nestedCount2 start
249+ *> sourceUnfoldrM nestedCount2 start
250+
251+ where
252+
253+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
254+
255+{-# INLINE apDiscardSnd #-}
256+apDiscardSnd :: MonadAsync m => Int -> Int -> m ()
257+apDiscardSnd linearCount start = drain $
258+ sourceUnfoldrM nestedCount2 start
259+ <* sourceUnfoldrM nestedCount2 start
260+
261+ where
262+
263+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
264+
265+{-# INLINE apLiftA2 #-}
266+apLiftA2 :: MonadAsync m => Int -> Int -> m ()
267+apLiftA2 linearCount start = drain $
268+ liftA2 (+) (sourceUnfoldrM nestedCount2 start)
269+ (sourceUnfoldrM nestedCount2 start)
270+
271+ where
272+
273+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
274+
275+{-# INLINE toNullAp #-}
276+toNullAp :: MonadAsync m => Int -> Int -> m ()
277+toNullAp linearCount start = drain $
278+ (+) <$> sourceUnfoldrM nestedCount2 start
279+ <*> sourceUnfoldrM nestedCount2 start
280+
281+ where
282+
283+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
284+
285+{-# INLINE monadThen #-}
286+monadThen :: MonadAsync m => Int -> Int -> m ()
287+monadThen linearCount start = drain $ do
288+ sourceUnfoldrM nestedCount2 start >>
289+ sourceUnfoldrM nestedCount2 start
290+
291+ where
292+
293+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
294+
295+{-# INLINE toNullM #-}
296+toNullM :: MonadAsync m => Int -> Int -> m ()
297+toNullM linearCount start = drain $ do
298+ x <- sourceUnfoldrM nestedCount2 start
299+ y <- sourceUnfoldrM nestedCount2 start
300+ return $ x + y
301+
302+ where
303+
304+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
305+
306+{-# INLINE toNullM3 #-}
307+toNullM3 :: MonadAsync m => Int -> Int -> m ()
308+toNullM3 linearCount start = drain $ do
309+ x <- sourceUnfoldrM nestedCount3 start
310+ y <- sourceUnfoldrM nestedCount3 start
311+ z <- sourceUnfoldrM nestedCount3 start
312+ return $ x + y + z
313+ where
314+ nestedCount3 = round (fromIntegral linearCount**(1/3::Double))
315+
316+{-# INLINE filterAllOutM #-}
317+filterAllOutM :: MonadAsync m => Int -> Int -> m ()
318+filterAllOutM linearCount start = drain $ do
319+ x <- sourceUnfoldrM nestedCount2 start
320+ y <- sourceUnfoldrM nestedCount2 start
321+ let s = x + y
322+ if s < 0
323+ then return s
324+ else Stream.nil
325+ where
326+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
327+
328+{-# INLINE filterAllInM #-}
329+filterAllInM :: MonadAsync m => Int -> Int -> m ()
330+filterAllInM linearCount start = drain $ do
331+ x <- sourceUnfoldrM nestedCount2 start
332+ y <- sourceUnfoldrM nestedCount2 start
333+ let s = x + y
334+ if s > 0
335+ then return s
336+ else Stream.nil
337+ where
338+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
339+
340+{-# INLINE filterSome #-}
341+filterSome :: MonadAsync m => Int -> Int -> m ()
342+filterSome linearCount start = drain $ do
343+ x <- sourceUnfoldrM nestedCount2 start
344+ y <- sourceUnfoldrM nestedCount2 start
345+ let s = x + y
346+ if s > 1100000
347+ then return s
348+ else Stream.nil
349+ where
350+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
351+
352+{-# INLINE breakAfterSome #-}
353+breakAfterSome :: Int -> Int -> IO ()
354+breakAfterSome linearCount start = do
355+ (_ :: Either ErrorCall ()) <- try $ drain $ do
356+ x <- sourceUnfoldrM nestedCount2 start
357+ y <- sourceUnfoldrM nestedCount2 start
358+ let s = x + y
359+ if s > 1100000
360+ then error "break"
361+ else return s
362+ return ()
363+ where
364+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
365+
366+{-# INLINE toListM #-}
367+toListM :: MonadAsync m => Int -> Int -> m [Int]
368+toListM linearCount start = Stream.fold Fold.toList $ do
369+ x <- sourceUnfoldrM nestedCount2 start
370+ y <- sourceUnfoldrM nestedCount2 start
371+ return $ x + y
372+ where
373+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
374+
375+-- Taking a specified number of elements is very expensive in logict so we have
376+-- a test to measure the same.
377+{-# INLINE toListSome #-}
378+toListSome :: MonadAsync m => Int -> Int -> m [Int]
379+toListSome linearCount start =
380+ Stream.fold Fold.toList $ Stream.take 10000 $ do
381+ x <- sourceUnfoldrM nestedCount2 start
382+ y <- sourceUnfoldrM nestedCount2 start
383+ return $ x + y
384+ where
385+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
386+
387+#ifndef USE_PRELUDE
388+{-# INLINE composeN #-}
389+composeN ::
390+ (Monad m)
391+ => Int
392+ -> (Stream m Int -> Stream m Int)
393+ -> Stream m Int
394+ -> m ()
395+composeN n f =
396+ case n of
397+ 1 -> drain . f
398+ 2 -> drain . f . f
399+ 3 -> drain . f . f . f
400+ 4 -> drain . f . f . f . f
401+ _ -> undefined
402+#endif
403+
404+{-# INLINE mapN #-}
405+mapN ::
406+ Monad m
407+ => Int
408+ -> Stream m Int
409+ -> m ()
410+mapN n = composeN n $ fmap (+ 1)
411+
412+{-# INLINE mapM #-}
413+mapM ::
414+ MonadAsync m
415+ => Int
416+ -> Stream m Int
417+ -> m ()
418+mapM n = composeN n $ Stream.mapM return
419+
420+#ifndef USE_PRELUDE
421+foldl' :: Monad m => (b -> a -> b) -> b -> Stream m a -> m b
422+foldl' f z = Stream.fold (Fold.foldl' f z)
423+
424+scanl' :: Monad m => (b -> a -> b) -> b -> Stream m a -> Stream m b
425+scanl' f z = Stream.scan (Fold.foldl' f z)
426+#endif
427+
428+{-# INLINE transformMapM #-}
429+transformMapM ::
430+ (Monad m)
431+ => Int
432+ -> Stream m Int
433+ -> m ()
434+transformMapM n = composeN n $ Stream.transform (Pipe.mapM return)
435+
436+{-# INLINE transformComposeMapM #-}
437+transformComposeMapM ::
438+ (Monad m)
439+ => Int
440+ -> Stream m Int
441+ -> m ()
442+transformComposeMapM n =
443+ composeN n $
444+ Stream.transform
445+ (Pipe.mapM (\x -> return (x + 1)) `Pipe.compose`
446+ Pipe.mapM (\x -> return (x + 2)))
447+
448+{-# INLINE transformTeeMapM #-}
449+transformTeeMapM ::
450+ (Monad m)
451+ => Int
452+ -> Stream m Int
453+ -> m ()
454+transformTeeMapM n =
455+ composeN n $
456+ Stream.transform
457+ (Pipe.mapM (\x -> return (x + 1)) `Pipe.tee`
458+ Pipe.mapM (\x -> return (x + 2)))
459+
460+{-# INLINE transformZipMapM #-}
461+transformZipMapM ::
462+ (Monad m)
463+ => Int
464+ -> Stream m Int
465+ -> m ()
466+transformZipMapM n =
467+ composeN n $
468+ Stream.transform
469+ (Pipe.zipWith
470+ (+)
471+ (Pipe.mapM (\x -> return (x + 1)))
472+ (Pipe.mapM (\x -> return (x + 2))))
benchmark/Streamly/Benchmark/Prelude/Serial/Elimination.hs → benchmark/Streamly/Benchmark/Data/Stream/Eliminate.hsrenamed+87−54
@@ -1,5 +1,5 @@
11-- |
2−-- Module : Serial.Elimination
2+-- Module : Stream.Eliminate
33-- Copyright : (c) 2018 Composewell Technologies
44-- License : BSD-3-Clause
55-- Maintainer : streamly@composewell.com
@@ -18,7 +18,7 @@
1818{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
1919#endif
2020
21−module Serial.Elimination (benchmarks) where
21+module Stream.Eliminate (benchmarks) where
2222
2323import Control.DeepSeq (NFData(..))
2424import Data.Functor.Identity (Identity, runIdentity)
@@ -33,21 +33,37 @@ import Test.Inspection
3333
3434import qualified Streamly.Internal.Data.Stream.StreamD as D
3535#endif
36−
37−import qualified Streamly.Prelude as S
38−import qualified Streamly.Internal.Data.Stream.IsStream as Internal
36+import qualified Streamly.Internal.Data.Fold as Fold
37+#ifdef USE_PRELUDE
38+import qualified Streamly.Internal.Data.Stream.IsStream as S
39+#else
40+import qualified Streamly.Internal.Data.Stream as S
41+#endif
3942
4043import Gauge
41−import Streamly.Prelude (SerialT, IsStream, fromSerial)
42−import Streamly.Benchmark.Common
44+-- XXX Replace SerialT with Stream
45+import Streamly.Internal.Data.Stream.Serial (SerialT)
46+#ifdef USE_PRELUDE
47+import Streamly.Prelude (fromSerial)
4348import Streamly.Benchmark.Prelude
49+#else
50+import Stream.Common
51+ ( sourceUnfoldr
52+ , sourceUnfoldrM
53+ , sourceUnfoldrAction
54+ , benchIOSink
55+ )
56+#endif
57+import Streamly.Benchmark.Common
4458import Prelude hiding (length, sum, or, and, any, all, notElem, elem, (!!),
4559 lookup, repeat, minimum, maximum, product, last, mapM_, init)
4660import qualified Prelude
4761
62+#ifdef USE_PRELUDE
4863{-# INLINE repeat #-}
4964repeat :: (Monad m, S.IsStream t) => Int -> Int -> t m Int
5065repeat count = S.take count . S.repeat
66+#endif
5167
5268-------------------------------------------------------------------------------
5369-- Elimination
@@ -60,76 +76,76 @@ repeat count = S.take count . S.repeat
6076{-# INLINE foldableFoldl' #-}
6177foldableFoldl' :: Int -> Int -> Int
6278foldableFoldl' value n =
63− F.foldl' (+) 0 (sourceUnfoldr value n :: S.SerialT Identity Int)
79+ F.foldl' (+) 0 (sourceUnfoldr value n :: SerialT Identity Int)
6480
6581{-# INLINE foldableFoldrElem #-}
6682foldableFoldrElem :: Int -> Int -> Bool
6783foldableFoldrElem value n =
6884 F.foldr (\x xs -> x == value || xs)
6985 False
70− (sourceUnfoldr value n :: S.SerialT Identity Int)
86+ (sourceUnfoldr value n :: SerialT Identity Int)
7187
7288{-# INLINE foldableSum #-}
7389foldableSum :: Int -> Int -> Int
7490foldableSum value n =
75− Prelude.sum (sourceUnfoldr value n :: S.SerialT Identity Int)
91+ Prelude.sum (sourceUnfoldr value n :: SerialT Identity Int)
7692
7793{-# INLINE foldableProduct #-}
7894foldableProduct :: Int -> Int -> Int
7995foldableProduct value n =
80− Prelude.product (sourceUnfoldr value n :: S.SerialT Identity Int)
96+ Prelude.product (sourceUnfoldr value n :: SerialT Identity Int)
8197
8298{-# INLINE _foldableNull #-}
8399_foldableNull :: Int -> Int -> Bool
84100_foldableNull value n =
85− Prelude.null (sourceUnfoldr value n :: S.SerialT Identity Int)
101+ Prelude.null (sourceUnfoldr value n :: SerialT Identity Int)
86102
87103{-# INLINE foldableElem #-}
88104foldableElem :: Int -> Int -> Bool
89105foldableElem value n =
90− value `Prelude.elem` (sourceUnfoldr value n :: S.SerialT Identity Int)
106+ value `Prelude.elem` (sourceUnfoldr value n :: SerialT Identity Int)
91107
92108{-# INLINE foldableNotElem #-}
93109foldableNotElem :: Int -> Int -> Bool
94110foldableNotElem value n =
95− value `Prelude.notElem` (sourceUnfoldr value n :: S.SerialT Identity Int)
111+ value `Prelude.notElem` (sourceUnfoldr value n :: SerialT Identity Int)
96112
97113{-# INLINE foldableFind #-}
98114foldableFind :: Int -> Int -> Maybe Int
99115foldableFind value n =
100− F.find (== (value + 1)) (sourceUnfoldr value n :: S.SerialT Identity Int)
116+ F.find (== (value + 1)) (sourceUnfoldr value n :: SerialT Identity Int)
101117
102118{-# INLINE foldableAll #-}
103119foldableAll :: Int -> Int -> Bool
104120foldableAll value n =
105− Prelude.all (<= (value + 1)) (sourceUnfoldr value n :: S.SerialT Identity Int)
121+ Prelude.all (<= (value + 1)) (sourceUnfoldr value n :: SerialT Identity Int)
106122
107123{-# INLINE foldableAny #-}
108124foldableAny :: Int -> Int -> Bool
109125foldableAny value n =
110− Prelude.any (> (value + 1)) (sourceUnfoldr value n :: S.SerialT Identity Int)
126+ Prelude.any (> (value + 1)) (sourceUnfoldr value n :: SerialT Identity Int)
111127
112128{-# INLINE foldableAnd #-}
113129foldableAnd :: Int -> Int -> Bool
114130foldableAnd value n =
115− Prelude.and $ S.map
116− (<= (value + 1)) (sourceUnfoldr value n :: S.SerialT Identity Int)
131+ Prelude.and $ fmap
132+ (<= (value + 1)) (sourceUnfoldr value n :: SerialT Identity Int)
117133
118134{-# INLINE foldableOr #-}
119135foldableOr :: Int -> Int -> Bool
120136foldableOr value n =
121− Prelude.or $ S.map
122− (> (value + 1)) (sourceUnfoldr value n :: S.SerialT Identity Int)
137+ Prelude.or $ fmap
138+ (> (value + 1)) (sourceUnfoldr value n :: SerialT Identity Int)
123139
124140{-# INLINE foldableLength #-}
125141foldableLength :: Int -> Int -> Int
126142foldableLength value n =
127− Prelude.length (sourceUnfoldr value n :: S.SerialT Identity Int)
143+ Prelude.length (sourceUnfoldr value n :: SerialT Identity Int)
128144
129145{-# INLINE foldableMin #-}
130146foldableMin :: Int -> Int -> Int
131147foldableMin value n =
132− Prelude.minimum (sourceUnfoldr value n :: S.SerialT Identity Int)
148+ Prelude.minimum (sourceUnfoldr value n :: SerialT Identity Int)
133149
134150{-# INLINE ordInstanceMin #-}
135151ordInstanceMin :: SerialT Identity Int -> SerialT Identity Int
@@ -138,12 +154,12 @@ ordInstanceMin src = min src src
138154{-# INLINE foldableMax #-}
139155foldableMax :: Int -> Int -> Int
140156foldableMax value n =
141− Prelude.maximum (sourceUnfoldr value n :: S.SerialT Identity Int)
157+ Prelude.maximum (sourceUnfoldr value n :: SerialT Identity Int)
142158
143159{-# INLINE foldableMinBy #-}
144160foldableMinBy :: Int -> Int -> Int
145161foldableMinBy value n =
146− F.minimumBy compare (sourceUnfoldr value n :: S.SerialT Identity Int)
162+ F.minimumBy compare (sourceUnfoldr value n :: SerialT Identity Int)
147163
148164{-# INLINE foldableListMinBy #-}
149165foldableListMinBy :: Int -> Int -> Int
@@ -152,27 +168,27 @@ foldableListMinBy value n = F.minimumBy compare [1..value+n]
152168{-# INLINE foldableMaxBy #-}
153169foldableMaxBy :: Int -> Int -> Int
154170foldableMaxBy value n =
155− F.maximumBy compare (sourceUnfoldr value n :: S.SerialT Identity Int)
171+ F.maximumBy compare (sourceUnfoldr value n :: SerialT Identity Int)
156172
157173{-# INLINE foldableToList #-}
158174foldableToList :: Int -> Int -> [Int]
159175foldableToList value n =
160− F.toList (sourceUnfoldr value n :: S.SerialT Identity Int)
176+ F.toList (sourceUnfoldr value n :: SerialT Identity Int)
161177
162178{-# INLINE foldableMapM_ #-}
163179foldableMapM_ :: Monad m => Int -> Int -> m ()
164180foldableMapM_ value n =
165− F.mapM_ (\_ -> return ()) (sourceUnfoldr value n :: S.SerialT Identity Int)
181+ F.mapM_ (\_ -> return ()) (sourceUnfoldr value n :: SerialT Identity Int)
166182
167183{-# INLINE foldableSequence_ #-}
168184foldableSequence_ :: Int -> Int -> IO ()
169185foldableSequence_ value n =
170− F.sequence_ (sourceUnfoldrAction value n :: S.SerialT Identity (IO Int))
186+ F.sequence_ (sourceUnfoldrAction value n :: SerialT Identity (IO Int))
171187
172188{-# INLINE _foldableMsum #-}
173189_foldableMsum :: Int -> Int -> IO Int
174190_foldableMsum value n =
175− F.msum (sourceUnfoldrAction value n :: S.SerialT Identity (IO Int))
191+ F.msum (sourceUnfoldrAction value n :: SerialT Identity (IO Int))
176192
177193{-# INLINE showInstance #-}
178194showInstance :: SerialT Identity Int -> String
@@ -240,8 +256,8 @@ benchPureSink value name = benchPure name (sourceUnfoldr value)
240256
241257{-# INLINE benchHoistSink #-}
242258benchHoistSink
243− :: (IsStream t, NFData b)
244− => Int -> String -> (t Identity Int -> IO b) -> Benchmark
259+ :: (NFData b)
260+ => Int -> String -> (SerialT Identity Int -> IO b) -> Benchmark
245261benchHoistSink value name f =
246262 bench name $ nfIO $ randomRIO (1,1) >>= f . sourceUnfoldr value
247263
@@ -249,8 +265,8 @@ benchHoistSink value name f =
249265-- we can't use it as it requires MonadAsync constraint.
250266{-# INLINE benchIdentitySink #-}
251267benchIdentitySink
252− :: (IsStream t, NFData b)
253− => Int -> String -> (t Identity Int -> Identity b) -> Benchmark
268+ :: (NFData b)
269+ => Int -> String -> (SerialT Identity Int -> Identity b) -> Benchmark
254270benchIdentitySink value name f = bench name $ nf (f . sourceUnfoldr value) 1
255271
256272-------------------------------------------------------------------------------
@@ -265,6 +281,7 @@ uncons s = do
265281 Nothing -> return ()
266282 Just (_, t) -> uncons t
267283
284+#ifdef USE_PRELUDE
268285{-# INLINE init #-}
269286init :: Monad m => SerialT m a -> m ()
270287init s = S.init s >>= Prelude.mapM_ S.drain
@@ -272,6 +289,7 @@ init s = S.init s >>= Prelude.mapM_ S.drain
272289{-# INLINE mapM_ #-}
273290mapM_ :: Monad m => SerialT m Int -> m ()
274291mapM_ = S.mapM_ (\_ -> return ())
292+#endif
275293
276294{-# INLINE foldrMElem #-}
277295foldrMElem :: Monad m => Int -> SerialT m Int -> m Bool
@@ -291,6 +309,7 @@ foldrToStream = S.foldr S.cons S.nil
291309foldrMBuild :: Monad m => SerialT m Int -> m [Int]
292310foldrMBuild = S.foldrM (\x xs -> (x :) <$> xs) (return [])
293311
312+#ifdef USE_PRELUDE
294313{-# INLINE foldl'Reduce #-}
295314foldl'Reduce :: Monad m => SerialT m Int -> m Int
296315foldl'Reduce = S.foldl' (+) 0
@@ -393,38 +412,43 @@ drainWhile = S.drainWhile (const True)
393412
394413{-# INLINE (!!) #-}
395414(!!) :: Monad m => Int -> SerialT m Int -> m (Maybe Int)
396−(!!) = flip (Internal.!!)
415+(!!) = flip (S.!!)
397416
398417{-# INLINE lookup #-}
399418lookup :: Monad m => Int -> SerialT m Int -> m (Maybe Int)
400419lookup val = S.lookup val . S.map (\x -> (x, x))
420+#endif
401421
402422o_1_space_elimination_folds :: Int -> [Benchmark]
403423o_1_space_elimination_folds value =
404424 [ bgroup "elimination"
405425 -- Basic folds
406− [ bgroup "reduce"
426+ [
427+#ifdef USE_PRELUDE
428+ bgroup "reduce"
407429 [ bgroup
408430 "IO"
409431 [ benchIOSink value "foldl'" foldl'Reduce
410432 , benchIOSink value "foldl1'" foldl1'Reduce
411433 , benchIOSink value "foldlM'" foldlM'Reduce
412434 ]
435+
413436 , bgroup
414437 "Identity"
415438 [ benchIdentitySink value "foldl'" foldl'Reduce
416439 , benchIdentitySink value "foldl1'" foldl1'Reduce
417440 , benchIdentitySink value "foldlM'" foldlM'Reduce
418441 ]
419− ]
420− , bgroup "build"
442+ ] ,
443+#endif
444+ bgroup "build"
421445 [ bgroup "IO"
422446 [ benchIOSink value "foldrMElem" (foldrMElem value)
423447 ]
424448 , bgroup "Identity"
425449 [ benchIdentitySink value "foldrMElem" (foldrMElem value)
426450 , benchIdentitySink value "foldrToStreamLength"
427− (S.length . runIdentity . foldrToStream)
451+ (S.fold Fold.length . runIdentity . foldrToStream)
428452 , benchPureSink value "foldrMToListLength"
429453 (Prelude.length . runIdentity . foldrMBuild)
430454 ]
@@ -432,6 +456,9 @@ o_1_space_elimination_folds value =
432456
433457 -- deconstruction
434458 , benchIOSink value "uncons" uncons
459+ , benchHoistSink value "length . generally"
460+ (S.fold Fold.length . S.generally)
461+#ifdef USE_PRELUDE
435462 , benchIOSink value "init" init
436463
437464 -- draining
@@ -445,8 +472,6 @@ o_1_space_elimination_folds value =
445472 -- , benchIOSink value "head" head
446473 , benchIOSink value "last" last
447474 , benchIOSink value "length" length
448− , benchHoistSink value "length . generally"
449− (length . Internal.generally)
450475 , benchIOSink value "sum" sum
451476 , benchIOSink value "product" product
452477 , benchIOSink value "maximumBy" maximumBy
@@ -470,6 +495,7 @@ o_1_space_elimination_folds value =
470495 , benchIOSink value "any" (any value)
471496 , benchIOSink value "and" (and value)
472497 , benchIOSink value "or" (or value)
498+#endif
473499
474500 -- length is used to check for foldr/build fusion
475501 , benchPureSink value "length . IsList.toList" (Prelude.length . GHC.toList)
@@ -480,6 +506,7 @@ o_1_space_elimination_folds value =
480506-- Buffered Transformations by fold
481507-------------------------------------------------------------------------------
482508
509+#ifdef USE_PRELUDE
483510{-# INLINE foldl'Build #-}
484511foldl'Build :: Monad m => SerialT m Int -> m [Int]
485512foldl'Build = S.foldl' (flip (:)) []
@@ -499,6 +526,7 @@ o_n_heap_elimination_foldl value =
499526 , benchIdentitySink value "foldlM'/build/Identity" foldlM'Build
500527 ]
501528 ]
529+#endif
502530
503531-- For comparisons
504532{-# INLINE showInstanceList #-}
@@ -534,13 +562,14 @@ o_n_space_elimination_foldr value =
534562 ]
535563 ]
536564
565+#ifdef USE_PRELUDE
537566o_n_heap_elimination_toList :: Int -> [Benchmark]
538567o_n_heap_elimination_toList value =
539568 [ bgroup "toList"
540569 -- Converting the stream to a list or pure stream in a strict monad
541− [ benchIOSink value "toListRev" Internal.toListRev
570+ [ benchIOSink value "toListRev" S.toListRev
542571 , benchIOSink value "toStreamRev"
543− (Internal.toStreamRev :: (SerialT IO Int -> IO (SerialT Identity Int)))
572+ (S.toStreamRev :: (SerialT IO Int -> IO (SerialT Identity Int)))
544573 ]
545574 ]
546575
@@ -550,9 +579,10 @@ o_n_space_elimination_toList value =
550579 -- Converting the stream to a list or pure stream in a strict monad
551580 [ benchIOSink value "toList" S.toList
552581 , benchIOSink value "toStream"
553− (Internal.toStream :: (SerialT IO Int -> IO (SerialT Identity Int)))
582+ (S.toStream :: (SerialT IO Int -> IO (SerialT Identity Int)))
554583 ]
555584 ]
585+#endif
556586
557587-------------------------------------------------------------------------------
558588-- Multi-stream folds
@@ -673,14 +703,17 @@ benchmarks moduleName size =
673703 , o_1_space_elimination_multi_stream_pure size
674704 , o_1_space_elimination_multi_stream size
675705 ]
676− , bgroup (o_n_heap_prefix moduleName) $ concat
677− [ o_n_heap_elimination_foldl size
678− , o_n_heap_elimination_toList size
679− , o_n_heap_elimination_buffered size
680− ]
681− , bgroup (o_n_space_prefix moduleName) $ concat
682− [ o_n_space_elimination_foldable size
683− , o_n_space_elimination_toList size
684− , o_n_space_elimination_foldr size
685− ]
706+
707+ , bgroup (o_n_heap_prefix moduleName) $
708+ o_n_heap_elimination_buffered size
709+#ifdef USE_PRELUDE
710+ ++ o_n_heap_elimination_foldl size
711+ ++ o_n_heap_elimination_toList size
712+#endif
713+ , bgroup (o_n_space_prefix moduleName) $
714+ o_n_space_elimination_foldable size
715+#ifdef USE_PRELUDE
716+ ++ o_n_space_elimination_toList size
717+#endif
718+ ++ o_n_space_elimination_foldr size
686719 ]
benchmark/Streamly/Benchmark/Prelude/Serial/Exceptions.hs → benchmark/Streamly/Benchmark/Data/Stream/Exceptions.hsrenamed+72−54
@@ -1,5 +1,5 @@
11-- |
2−-- Module : Streamly.Benchmark.Prelude.Serial.Exceptions
2+-- Module : Stream.Exceptions
33-- Copyright : (c) 2019 Composewell Technologies
44-- License : BSD-3-Clause
55-- Maintainer : streamly@composewell.com
@@ -7,6 +7,7 @@
77-- Portability : GHC
88
99{-# LANGUAGE CPP #-}
10+{-# LANGUAGE FlexibleContexts #-}
1011{-# LANGUAGE ScopedTypeVariables #-}
1112
1213#ifdef __HADDOCK_VERSION__
@@ -18,19 +19,25 @@
1819{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
1920#endif
2021
21−module Serial.Exceptions (benchmarks) where
22+module Stream.Exceptions (benchmarks) where
2223
2324import Control.Exception (SomeException, Exception, throwIO)
25+import Stream.Common (drain, enumerateFromTo)
26+import Streamly.Internal.Data.Stream.Serial (SerialT)
2427import System.IO (Handle, hClose, hPutChar)
2528
2629import qualified Data.IORef as Ref
2730import qualified Data.Map.Strict as Map
28−
31+import qualified Stream.Common as Common
2932import qualified Streamly.FileSystem.Handle as FH
3033import qualified Streamly.Internal.Data.Unfold as IUF
3134import qualified Streamly.Internal.FileSystem.Handle as IFH
32−import qualified Streamly.Internal.Data.Stream.IsStream as IP
33−import qualified Streamly.Prelude as S
35+#ifdef USE_PRELUDE
36+import qualified Streamly.Internal.Data.Stream.IsStream as Stream
37+#else
38+import qualified Streamly.Internal.Data.Stream as Stream
39+import qualified Streamly.Internal.Data.Unfold as Unfold
40+#endif
3441
3542import Gauge hiding (env)
3643import Prelude hiding (last, length)
@@ -47,6 +54,14 @@ import qualified Streamly.Internal.Data.Stream.StreamD as D
4754-- stream exceptions
4855-------------------------------------------------------------------------------
4956
57+{-# INLINE replicateM #-}
58+replicateM :: Common.MonadAsync m => Int -> m a -> SerialT m a
59+#ifdef USE_PRELUDE
60+replicateM = Stream.replicateM
61+#else
62+replicateM = Stream.unfold . Unfold.replicateM
63+#endif
64+
5065data BenchException
5166 = BenchException1
5267 | BenchException2
@@ -56,37 +71,41 @@ instance Exception BenchException
5671
5772retryNoneSimple :: Int -> Int -> IO ()
5873retryNoneSimple length from =
59− IP.drain
60− $ IP.retry (Map.singleton BenchException1 length) (const S.nil) source
74+ drain
75+ $ Stream.retry
76+ (Map.singleton BenchException1 length)
77+ (const Stream.nil)
78+ source
6179
6280 where
6381
64− source = S.enumerateFromTo from (from + length)
82+ source = enumerateFromTo from (from + length)
6583
6684retryNone :: Int -> Int -> IO ()
6785retryNone length from = do
6886 ref <- Ref.newIORef (0 :: Int)
69− IP.drain
70− $ IP.retry (Map.singleton BenchException1 length) (const S.nil)
87+ drain
88+ $ Stream.retry (Map.singleton BenchException1 length) (const Stream.nil)
7189 $ source ref
7290
7391 where
7492
7593 source ref =
76− IP.replicateM (from + length)
94+ replicateM (from + length)
7795 $ Ref.modifyIORef' ref (+ 1) >> Ref.readIORef ref
7896
7997retryAll :: Int -> Int -> IO ()
8098retryAll length from = do
8199 ref <- Ref.newIORef 0
82− IP.drain
83− $ IP.retry (Map.singleton BenchException1 (length + from)) (const S.nil)
100+ drain
101+ $ Stream.retry
102+ (Map.singleton BenchException1 (length + from)) (const Stream.nil)
84103 $ source ref
85104
86105 where
87106
88107 source ref =
89− IP.fromEffect
108+ Stream.fromEffect
90109 $ do
91110 Ref.modifyIORef' ref (+ 1)
92111 val <- Ref.readIORef ref
@@ -96,13 +115,13 @@ retryAll length from = do
96115
97116retryUnknown :: Int -> Int -> IO ()
98117retryUnknown length from = do
99− IP.drain
100− $ IP.retry (Map.singleton BenchException1 length) (const source)
101− $ throwIO BenchException2 `S.before` S.nil
118+ drain
119+ $ Stream.retry (Map.singleton BenchException1 length) (const source)
120+ $ throwIO BenchException2 `Stream.before` Stream.nil
102121
103122 where
104123
105− source = S.enumerateFromTo from (from + length)
124+ source = enumerateFromTo from (from + length)
106125
107126
108127o_1_space_serial_exceptions :: Int -> [Benchmark]
@@ -123,8 +142,8 @@ o_1_space_serial_exceptions length =
123142-- | Send the file contents to /dev/null with exception handling
124143readWriteOnExceptionStream :: Handle -> Handle -> IO ()
125144readWriteOnExceptionStream inh devNull =
126− let readEx = S.onException (hClose inh) (S.unfold FH.read inh)
127− in S.fold (FH.write devNull) $ readEx
145+ let readEx = Stream.onException (hClose inh) (Stream.unfold FH.read inh)
146+ in Stream.fold (FH.write devNull) readEx
128147
129148#ifdef INSPECTION
130149inspect $ hasNoTypeClasses 'readWriteOnExceptionStream
@@ -133,9 +152,9 @@ inspect $ hasNoTypeClasses 'readWriteOnExceptionStream
133152-- | Send the file contents to /dev/null with exception handling
134153readWriteHandleExceptionStream :: Handle -> Handle -> IO ()
135154readWriteHandleExceptionStream inh devNull =
136− let handler (_e :: SomeException) = S.fromEffect (hClose inh >> return 10)
137− readEx = S.handle handler (S.unfold FH.read inh)
138− in S.fold (FH.write devNull) $ readEx
155+ let handler (_e :: SomeException) = Stream.fromEffect (hClose inh >> return 10)
156+ readEx = Stream.handle handler (Stream.unfold FH.read inh)
157+ in Stream.fold (FH.write devNull) readEx
139158
140159#ifdef INSPECTION
141160inspect $ hasNoTypeClasses 'readWriteHandleExceptionStream
@@ -144,8 +163,8 @@ inspect $ hasNoTypeClasses 'readWriteHandleExceptionStream
144163-- | Send the file contents to /dev/null with exception handling
145164readWriteFinally_Stream :: Handle -> Handle -> IO ()
146165readWriteFinally_Stream inh devNull =
147− let readEx = IP.finally_ (hClose inh) (S.unfold FH.read inh)
148− in S.fold (FH.write devNull) readEx
166+ let readEx = Stream.finally_ (hClose inh) (Stream.unfold FH.read inh)
167+ in Stream.fold (FH.write devNull) readEx
149168
150169#ifdef INSPECTION
151170inspect $ hasNoTypeClasses 'readWriteFinally_Stream
@@ -153,15 +172,15 @@ inspect $ hasNoTypeClasses 'readWriteFinally_Stream
153172
154173readWriteFinallyStream :: Handle -> Handle -> IO ()
155174readWriteFinallyStream inh devNull =
156− let readEx = S.finally (hClose inh) (S.unfold FH.read inh)
157− in S.fold (FH.write devNull) readEx
175+ let readEx = Stream.finally (hClose inh) (Stream.unfold FH.read inh)
176+ in Stream.fold (FH.write devNull) readEx
158177
159178-- | Send the file contents to /dev/null with exception handling
160179fromToBytesBracket_Stream :: Handle -> Handle -> IO ()
161180fromToBytesBracket_Stream inh devNull =
162− let readEx = IP.bracket_ (return ()) (\_ -> hClose inh)
181+ let readEx = Stream.bracket_ (return ()) (\_ -> hClose inh)
163182 (\_ -> IFH.getBytes inh)
164− in IFH.putBytes devNull $ readEx
183+ in IFH.putBytes devNull readEx
165184
166185#ifdef INSPECTION
167186inspect $ hasNoTypeClasses 'fromToBytesBracket_Stream
@@ -169,16 +188,16 @@ inspect $ hasNoTypeClasses 'fromToBytesBracket_Stream
169188
170189fromToBytesBracketStream :: Handle -> Handle -> IO ()
171190fromToBytesBracketStream inh devNull =
172− let readEx = S.bracket (return ()) (\_ -> hClose inh)
191+ let readEx = Stream.bracket (return ()) (\_ -> hClose inh)
173192 (\_ -> IFH.getBytes inh)
174− in IFH.putBytes devNull $ readEx
193+ in IFH.putBytes devNull readEx
175194
176195readWriteBeforeAfterStream :: Handle -> Handle -> IO ()
177196readWriteBeforeAfterStream inh devNull =
178197 let readEx =
179− IP.after (hClose inh)
180− $ IP.before (hPutChar devNull 'A') (S.unfold FH.read inh)
181− in S.fold (FH.write devNull) readEx
198+ Stream.after (hClose inh)
199+ $ Stream.before (hPutChar devNull 'A') (Stream.unfold FH.read inh)
200+ in Stream.fold (FH.write devNull) readEx
182201
183202#ifdef INSPECTION
184203inspect $ 'readWriteBeforeAfterStream `hasNoType` ''D.Step
@@ -186,8 +205,8 @@ inspect $ 'readWriteBeforeAfterStream `hasNoType` ''D.Step
186205
187206readWriteAfterStream :: Handle -> Handle -> IO ()
188207readWriteAfterStream inh devNull =
189− let readEx = IP.after (hClose inh) (S.unfold FH.read inh)
190− in S.fold (FH.write devNull) readEx
208+ let readEx = Stream.after (hClose inh) (Stream.unfold FH.read inh)
209+ in Stream.fold (FH.write devNull) readEx
191210
192211#ifdef INSPECTION
193212inspect $ 'readWriteAfterStream `hasNoType` ''D.Step
@@ -195,8 +214,8 @@ inspect $ 'readWriteAfterStream `hasNoType` ''D.Step
195214
196215readWriteAfter_Stream :: Handle -> Handle -> IO ()
197216readWriteAfter_Stream inh devNull =
198− let readEx = IP.after_ (hClose inh) (S.unfold FH.read inh)
199− in S.fold (FH.write devNull) readEx
217+ let readEx = Stream.after_ (hClose inh) (Stream.unfold FH.read inh)
218+ in Stream.fold (FH.write devNull) readEx
200219
201220#ifdef INSPECTION
202221inspect $ hasNoTypeClasses 'readWriteAfter_Stream
@@ -206,25 +225,25 @@ inspect $ 'readWriteAfter_Stream `hasNoType` ''D.Step
206225o_1_space_copy_stream_exceptions :: BenchEnv -> [Benchmark]
207226o_1_space_copy_stream_exceptions env =
208227 [ bgroup "exceptions"
209− [ mkBenchSmall "S.onException" env $ \inh _ ->
228+ [ mkBenchSmall "Stream.onException" env $ \inh _ ->
210229 readWriteOnExceptionStream inh (nullH env)
211− , mkBenchSmall "S.handle" env $ \inh _ ->
230+ , mkBenchSmall "Stream.handle" env $ \inh _ ->
212231 readWriteHandleExceptionStream inh (nullH env)
213− , mkBenchSmall "S.finally_" env $ \inh _ ->
232+ , mkBenchSmall "Stream.finally_" env $ \inh _ ->
214233 readWriteFinally_Stream inh (nullH env)
215− , mkBenchSmall "S.finally" env $ \inh _ ->
234+ , mkBenchSmall "Stream.finally" env $ \inh _ ->
216235 readWriteFinallyStream inh (nullH env)
217− , mkBenchSmall "S.after . S.before" env $ \inh _ ->
236+ , mkBenchSmall "Stream.after . Stream.before" env $ \inh _ ->
218237 readWriteBeforeAfterStream inh (nullH env)
219− , mkBenchSmall "S.after" env $ \inh _ ->
238+ , mkBenchSmall "Stream.after" env $ \inh _ ->
220239 readWriteAfterStream inh (nullH env)
221− , mkBenchSmall "S.after_" env $ \inh _ ->
240+ , mkBenchSmall "Stream.after_" env $ \inh _ ->
222241 readWriteAfter_Stream inh (nullH env)
223242 ]
224243 , bgroup "exceptions/fromToBytes"
225− [ mkBenchSmall "S.bracket_" env $ \inh _ ->
244+ [ mkBenchSmall "Stream.bracket_" env $ \inh _ ->
226245 fromToBytesBracket_Stream inh (nullH env)
227− , mkBenchSmall "S.bracket" env $ \inh _ ->
246+ , mkBenchSmall "Stream.bracket" env $ \inh _ ->
228247 fromToBytesBracketStream inh (nullH env)
229248 ]
230249 ]
@@ -277,11 +296,11 @@ o_1_space_copy_exceptions_readChunks env =
277296-- | Send the file contents to /dev/null with exception handling
278297toChunksBracket_ :: Handle -> Handle -> IO ()
279298toChunksBracket_ inh devNull =
280− let readEx = IP.bracket_
299+ let readEx = Stream.bracket_
281300 (return ())
282301 (\_ -> hClose inh)
283302 (\_ -> IFH.getChunks inh)
284− in S.fold (IFH.writeChunks devNull) $ readEx
303+ in Stream.fold (IFH.writeChunks devNull) readEx
285304
286305#ifdef INSPECTION
287306inspect $ hasNoTypeClasses 'toChunksBracket_
@@ -289,23 +308,22 @@ inspect $ hasNoTypeClasses 'toChunksBracket_
289308
290309toChunksBracket :: Handle -> Handle -> IO ()
291310toChunksBracket inh devNull =
292− let readEx = S.bracket
311+ let readEx = Stream.bracket
293312 (return ())
294313 (\_ -> hClose inh)
295314 (\_ -> IFH.getChunks inh)
296− in S.fold (IFH.writeChunks devNull) $ readEx
315+ in Stream.fold (IFH.writeChunks devNull) readEx
297316
298317o_1_space_copy_exceptions_toChunks :: BenchEnv -> [Benchmark]
299318o_1_space_copy_exceptions_toChunks env =
300319 [ bgroup "exceptions/toChunks"
301− [ mkBench "S.bracket_" env $ \inH _ ->
320+ [ mkBench "Stream.bracket_" env $ \inH _ ->
302321 toChunksBracket_ inH (nullH env)
303− , mkBench "S.bracket" env $ \inH _ ->
322+ , mkBench "Stream.bracket" env $ \inH _ ->
304323 toChunksBracket inH (nullH env)
305324 ]
306325 ]
307326
308−
309327benchmarks :: String -> BenchEnv -> Int -> [Benchmark]
310328benchmarks moduleName env size =
311329 [ bgroup (o_1_space_prefix moduleName) $ concat
benchmark/Streamly/Benchmark/Prelude/Serial/NestedStream.hs → benchmark/Streamly/Benchmark/Data/Stream/Expand.hsrenamed+86−70
@@ -1,5 +1,5 @@
11-- |
2−-- Module : Serial.NestedStream
2+-- Module : Stream.Expand
33-- Copyright : (c) 2018 Composewell Technologies
44-- License : BSD-3-Clause
55-- Maintainer : streamly@composewell.com
@@ -18,9 +18,10 @@
1818{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
1919#endif
2020
21−module Serial.NestedStream (benchmarks) where
21+module Stream.Expand (benchmarks) where
2222
2323import Control.Monad.Trans.Class (lift)
24+import Streamly.Internal.Data.Stream.Serial (SerialT)
2425
2526import qualified Control.Applicative as AP
2627
@@ -31,14 +32,23 @@ import Test.Inspection
3132import qualified Streamly.Internal.Data.Stream.StreamD as D
3233#endif
3334
34−import qualified Streamly.Prelude as S
35−import qualified Streamly.Internal.Data.Stream.IsStream as Internal
35+import qualified Stream.Common as Common
36+#ifdef USE_PRELUDE
37+import qualified Streamly.Internal.Data.Stream.IsStream as S
38+import Streamly.Benchmark.Prelude hiding
39+ (benchIOSrc, sourceUnfoldrM, apDiscardFst, apDiscardSnd, apLiftA2, toNullAp
40+ , monadThen, toNullM, toNullM3, filterAllInM, filterAllOutM, filterSome
41+ , breakAfterSome, toListM, toListSome)
42+#else
43+import Streamly.Benchmark.Prelude (benchIO)
44+import qualified Streamly.Internal.Data.Stream as S
45+#endif
3646import qualified Streamly.Internal.Data.Unfold as UF
47+import qualified Streamly.Internal.Data.Fold as Fold
3748
3849import Gauge
39−import Streamly.Prelude (SerialT, fromSerial, serial)
50+import Stream.Common hiding (append2)
4051import Streamly.Benchmark.Common
41−import Streamly.Benchmark.Prelude
4252import Prelude hiding (concatMap)
4353
4454-------------------------------------------------------------------------------
@@ -56,13 +66,14 @@ iterateN g initial count = f count initial
5666
5767-- Iterate a transformation over a singleton stream
5868{-# INLINE iterateSingleton #-}
59−iterateSingleton :: S.MonadAsync m
69+iterateSingleton :: Monad m
6070 => (Int -> SerialT m Int -> SerialT m Int)
6171 -> Int
6272 -> Int
6373 -> SerialT m Int
6474iterateSingleton g count n = iterateN g (return n) count
6575
76+{-
6677-- XXX need to check why this is slower than the explicit recursion above, even
6778-- if the above code is written in a foldr like head recursive way. We also
6879-- need to try this with foldlM' once #150 is fixed.
@@ -70,12 +81,13 @@ iterateSingleton g count n = iterateN g (return n) count
7081-- foldrM and any related fusion issues.
7182{-# INLINE _iterateSingleton #-}
7283_iterateSingleton ::
73− S.MonadAsync m
84+ Monad m
7485 => (Int -> SerialT m Int -> SerialT m Int)
7586 -> Int
7687 -> Int
7788 -> SerialT m Int
7889_iterateSingleton g value n = S.foldrM g (return n) $ sourceIntFromTo value n
90+-}
7991
8092-------------------------------------------------------------------------------
8193-- Multi-Stream
@@ -88,34 +100,34 @@ _iterateSingleton g value n = S.foldrM g (return n) $ sourceIntFromTo value n
88100{-# INLINE serial2 #-}
89101serial2 :: Int -> Int -> IO ()
90102serial2 count n =
91− S.drain $
92− S.serial (sourceUnfoldrM count n) (sourceUnfoldrM count (n + 1))
103+ drain $
104+ Common.append (sourceUnfoldrM count n) (sourceUnfoldrM count (n + 1))
93105
94106{-# INLINE serial4 #-}
95107serial4 :: Int -> Int -> IO ()
96108serial4 count n =
97− S.drain $
98− S.serial
99− (S.serial (sourceUnfoldrM count n) (sourceUnfoldrM count (n + 1)))
100− (S.serial
109+ drain $
110+ Common.append
111+ (Common.append (sourceUnfoldrM count n) (sourceUnfoldrM count (n + 1)))
112+ (Common.append
101113 (sourceUnfoldrM count (n + 2))
102114 (sourceUnfoldrM count (n + 3)))
103115
104116{-# INLINE append2 #-}
105117append2 :: Int -> Int -> IO ()
106118append2 count n =
107− S.drain $
108− Internal.append (sourceUnfoldrM count n) (sourceUnfoldrM count (n + 1))
119+ drain $
120+ Common.append2 (sourceUnfoldrM count n) (sourceUnfoldrM count (n + 1))
109121
110122{-# INLINE append4 #-}
111123append4 :: Int -> Int -> IO ()
112124append4 count n =
113− S.drain $
114− Internal.append
115− (Internal.append
125+ drain $
126+ Common.append2
127+ (Common.append2
116128 (sourceUnfoldrM count n)
117129 (sourceUnfoldrM count (n + 1)))
118− (Internal.append
130+ (Common.append2
119131 (sourceUnfoldrM count (n + 2))
120132 (sourceUnfoldrM count (n + 3)))
121133
@@ -139,22 +151,24 @@ o_1_space_joining value =
139151-- Concat Foldable containers
140152-------------------------------------------------------------------------------
141153
154+#ifdef USE_PRELUDE
142155o_1_space_concatFoldable :: Int -> [Benchmark]
143156o_1_space_concatFoldable value =
144157 [ bgroup "concat-foldable"
145− [ benchIOSrc fromSerial "foldMapWith (<>) (List)"
158+ [ benchIOSrc "foldMapWith (<>) (List)"
146159 (sourceFoldMapWith value)
147− , benchIOSrc fromSerial "foldMapWith (<>) (Stream)"
160+ , benchIOSrc "foldMapWith (<>) (Stream)"
148161 (sourceFoldMapWithStream value)
149− , benchIOSrc fromSerial "foldMapWithM (<>) (List)"
162+ , benchIOSrc "foldMapWithM (<>) (List)"
150163 (sourceFoldMapWithM value)
151− , benchIOSrc fromSerial "S.concatFoldableWith (<>) (List)"
164+ , benchIOSrc "S.concatFoldableWith (<>) (List)"
152165 (concatFoldableWith value)
153− , benchIOSrc fromSerial "S.concatForFoldableWith (<>) (List)"
166+ , benchIOSrc "S.concatForFoldableWith (<>) (List)"
154167 (concatForFoldableWith value)
155− , benchIOSrc fromSerial "foldMapM (List)" (sourceFoldMapM value)
168+ , benchIOSrc "foldMapM (List)" (sourceFoldMapM value)
156169 ]
157170 ]
171+#endif
158172
159173-------------------------------------------------------------------------------
160174-- Concat
@@ -165,14 +179,14 @@ o_1_space_concatFoldable value =
165179{-# INLINE concatMap #-}
166180concatMap :: Int -> Int -> Int -> IO ()
167181concatMap outer inner n =
168− S.drain $ S.concatMap
182+ drain $ S.concatMap
169183 (\_ -> sourceUnfoldrM inner n)
170184 (sourceUnfoldrM outer n)
171185
172186{-# INLINE concatMapM #-}
173187concatMapM :: Int -> Int -> Int -> IO ()
174188concatMapM outer inner n =
175− S.drain $ S.concatMapM
189+ drain $ S.concatMapM
176190 (\_ -> return $ sourceUnfoldrM inner n)
177191 (sourceUnfoldrM outer n)
178192
@@ -186,7 +200,7 @@ inspect $ 'concatMap `hasNoType` ''SPEC
186200{-# INLINE concatMapPure #-}
187201concatMapPure :: Int -> Int -> Int -> IO ()
188202concatMapPure outer inner n =
189− S.drain $ S.concatMap
203+ drain $ S.concatMap
190204 (\_ -> sourceUnfoldr inner n)
191205 (sourceUnfoldr outer n)
192206
@@ -200,7 +214,7 @@ inspect $ 'concatMapPure `hasNoType` ''SPEC
200214{-# INLINE concatMapRepl #-}
201215concatMapRepl :: Int -> Int -> Int -> IO ()
202216concatMapRepl outer inner n =
203− S.drain $ S.concatMap (S.replicate inner) (sourceUnfoldrM outer n)
217+ drain $ S.concatMap (Common.replicate inner) (sourceUnfoldrM outer n)
204218
205219#ifdef INSPECTION
206220inspect $ hasNoTypeClasses 'concatMapRepl
@@ -211,7 +225,7 @@ inspect $ 'concatMapRepl `hasNoType` ''SPEC
211225
212226{-# INLINE concatMapWithSerial #-}
213227concatMapWithSerial :: Int -> Int -> Int -> IO ()
214−concatMapWithSerial = concatStreamsWith S.serial
228+concatMapWithSerial = concatStreamsWith Common.append
215229
216230#ifdef INSPECTION
217231inspect $ hasNoTypeClasses 'concatMapWithSerial
@@ -220,7 +234,7 @@ inspect $ 'concatMapWithSerial `hasNoType` ''SPEC
220234
221235{-# INLINE concatMapWithAppend #-}
222236concatMapWithAppend :: Int -> Int -> Int -> IO ()
223−concatMapWithAppend = concatStreamsWith Internal.append
237+concatMapWithAppend = concatStreamsWith Common.append2
224238
225239#ifdef INSPECTION
226240inspect $ hasNoTypeClasses 'concatMapWithAppend
@@ -231,11 +245,11 @@ inspect $ 'concatMapWithAppend `hasNoType` ''SPEC
231245
232246{-# INLINE concatPairWithSerial #-}
233247concatPairWithSerial :: Int -> Int -> Int -> IO ()
234−concatPairWithSerial = concatPairsWith Internal.serial
248+concatPairWithSerial = concatPairsWith Common.append
235249
236250{-# INLINE concatPairWithAppend #-}
237251concatPairWithAppend :: Int -> Int -> Int -> IO ()
238−concatPairWithAppend = concatPairsWith Internal.append
252+concatPairWithAppend = concatPairsWith Common.append2
239253
240254-- unfoldMany
241255
@@ -244,7 +258,7 @@ concatPairWithAppend = concatPairsWith Internal.append
244258{-# INLINE unfoldManyRepl #-}
245259unfoldManyRepl :: Int -> Int -> Int -> IO ()
246260unfoldManyRepl outer inner n =
247− S.drain
261+ drain
248262 $ S.unfoldMany
249263 (UF.lmap return (UF.replicateM inner))
250264 (sourceUnfoldrM outer n)
@@ -266,7 +280,7 @@ o_1_space_concat value = sqrtVal `seq`
266280 (concatMapPure 1 value)
267281
268282 -- This is for comparison with foldMapWith
269− , benchIOSrc fromSerial "concatMapId (n of 1) (fromFoldable)"
283+ , benchIOSrc "concatMapId (n of 1) (fromFoldable)"
270284 (S.concatMap id . sourceConcatMapId value)
271285
272286 , benchIOSrc1 "concatMap (n of 1)"
@@ -284,8 +298,8 @@ o_1_space_concat value = sqrtVal `seq`
284298 (concatMapM 1 value)
285299
286300 -- This is for comparison with foldMapWith
287− , benchIOSrc fromSerial "concatMapWithId (n of 1) (fromFoldable)"
288− (S.concatMapWith serial id . sourceConcatMapId value)
301+ , benchIOSrc "concatMapWithId (n of 1) (fromFoldable)"
302+ (S.concatMapWith Common.append id . sourceConcatMapId value)
289303
290304 , benchIOSrc1 "concatMapWith (n of 1)"
291305 (concatMapWithSerial value 1)
@@ -343,23 +357,23 @@ o_n_space_concat value = sqrtVal `seq`
343357o_1_space_applicative :: Int -> [Benchmark]
344358o_1_space_applicative value =
345359 [ bgroup "Applicative"
346− [ benchIO "(*>) (sqrt n x sqrt n)" $ apDiscardFst value fromSerial
347− , benchIO "(<*) (sqrt n x sqrt n)" $ apDiscardSnd value fromSerial
348− , benchIO "(<*>) (sqrt n x sqrt n)" $ toNullAp value fromSerial
349− , benchIO "liftA2 (sqrt n x sqrt n)" $ apLiftA2 value fromSerial
360+ [ benchIO "(*>) (sqrt n x sqrt n)" $ apDiscardFst value
361+ , benchIO "(<*) (sqrt n x sqrt n)" $ apDiscardSnd value
362+ , benchIO "(<*>) (sqrt n x sqrt n)" $ toNullAp value
363+ , benchIO "liftA2 (sqrt n x sqrt n)" $ apLiftA2 value
350364 ]
351365 ]
352366
353367o_n_space_applicative :: Int -> [Benchmark]
354368o_n_space_applicative value =
355369 [ bgroup "Applicative"
356− [ benchIOSrc fromSerial "(*>) (n times)" $
370+ [ benchIOSrc "(*>) (n times)" $
357371 iterateSingleton ((*>) . pure) value
358− , benchIOSrc fromSerial "(<*) (n times)" $
372+ , benchIOSrc "(<*) (n times)" $
359373 iterateSingleton (\x xs -> xs <* pure x) value
360− , benchIOSrc fromSerial "(<*>) (n times)" $
374+ , benchIOSrc "(<*>) (n times)" $
361375 iterateSingleton (\x xs -> pure (+ x) <*> xs) value
362− , benchIOSrc fromSerial "liftA2 (n times)" $
376+ , benchIOSrc "liftA2 (n times)" $
363377 iterateSingleton (AP.liftA2 (+) . pure) value
364378 ]
365379 ]
@@ -371,18 +385,18 @@ o_n_space_applicative value =
371385o_1_space_monad :: Int -> [Benchmark]
372386o_1_space_monad value =
373387 [ bgroup "Monad"
374− [ benchIO "(>>) (sqrt n x sqrt n)" $ monadThen value fromSerial
375− , benchIO "(>>=) (sqrt n x sqrt n)" $ toNullM value fromSerial
388+ [ benchIO "(>>) (sqrt n x sqrt n)" $ monadThen value
389+ , benchIO "(>>=) (sqrt n x sqrt n)" $ toNullM value
376390 , benchIO "(>>=) (sqrt n x sqrt n) (filterAllOut)" $
377− filterAllOutM value fromSerial
391+ filterAllOutM value
378392 , benchIO "(>>=) (sqrt n x sqrt n) (filterAllIn)" $
379− filterAllInM value fromSerial
393+ filterAllInM value
380394 , benchIO "(>>=) (sqrt n x sqrt n) (filterSome)" $
381− filterSome value fromSerial
395+ filterSome value
382396 , benchIO "(>>=) (sqrt n x sqrt n) (breakAfterSome)" $
383− breakAfterSome value fromSerial
397+ breakAfterSome value
384398 , benchIO "(>>=) (cubert n x cubert n x cubert n)" $
385− toNullM3 value fromSerial
399+ toNullM3 value
386400 ]
387401 ]
388402
@@ -400,16 +414,16 @@ sieve s = do
400414o_n_space_monad :: Int -> [Benchmark]
401415o_n_space_monad value =
402416 [ bgroup "Monad"
403− [ benchIOSrc fromSerial "(>>) (n times)" $
417+ [ benchIOSrc "(>>) (n times)" $
404418 iterateSingleton ((>>) . pure) value
405− , benchIOSrc fromSerial "(>>=) (n times)" $
419+ , benchIOSrc "(>>=) (n times)" $
406420 iterateSingleton (\x xs -> xs >>= \y -> return (x + y)) value
407421 , benchIO "(>>=) (sqrt n x sqrt n) (toList)" $
408− toListM value fromSerial
422+ toListM value
409423 , benchIO "(>>=) (sqrt n x sqrt n) (toListSome)" $
410− toListSome value fromSerial
424+ toListSome value
411425 , benchIO "naive prime sieve (n/4)"
412− (\n -> S.sum $ sieve $ S.enumerateFromTo 2 (value `div` 4 + n))
426+ (\n -> S.fold Fold.sum $ sieve $ enumerateFromTo 2 (value `div` 4 + n))
413427 ]
414428 ]
415429
@@ -421,22 +435,22 @@ toKv :: Int -> (Int, Int)
421435toKv p = (p, p)
422436
423437{-# INLINE joinWith #-}
424−joinWith :: (S.MonadAsync m) =>
438+joinWith :: Common.MonadAsync m =>
425439 ((Int -> Int -> Bool) -> SerialT m Int -> SerialT m Int -> SerialT m b)
426440 -> Int
427441 -> Int
428442 -> m ()
429443joinWith j val i =
430− S.drain $ j (==) (sourceUnfoldrM val i) (sourceUnfoldrM val (val `div` 2))
444+ drain $ j (==) (sourceUnfoldrM val i) (sourceUnfoldrM val (val `div` 2))
431445
432446{-# INLINE joinMapWith #-}
433−joinMapWith :: (S.MonadAsync m) =>
447+joinMapWith :: Common.MonadAsync m =>
434448 (SerialT m (Int, Int) -> SerialT m (Int, Int) -> SerialT m b)
435449 -> Int
436450 -> Int
437451 -> m ()
438452joinMapWith j val i =
439− S.drain
453+ drain
440454 $ j
441455 (fmap toKv (sourceUnfoldrM val i))
442456 (fmap toKv (sourceUnfoldrM val (val `div` 2)))
@@ -446,21 +460,21 @@ o_n_heap_buffering value =
446460 [ bgroup "buffered"
447461 [
448462 benchIOSrc1 "joinInner (sqrtVal)"
449− $ joinWith Internal.joinInner sqrtVal
463+ $ joinWith S.joinInner sqrtVal
450464 , benchIOSrc1 "joinInnerMap"
451− $ joinMapWith Internal.joinInnerMap halfVal
465+ $ joinMapWith S.joinInnerMap halfVal
452466 , benchIOSrc1 "joinLeft (sqrtVal)"
453− $ joinWith Internal.joinLeft sqrtVal
467+ $ joinWith S.joinLeft sqrtVal
454468 , benchIOSrc1 "joinLeftMap "
455− $ joinMapWith Internal.joinLeftMap halfVal
469+ $ joinMapWith S.joinLeftMap halfVal
456470 , benchIOSrc1 "joinOuter (sqrtVal)"
457− $ joinWith Internal.joinOuter sqrtVal
471+ $ joinWith S.joinOuter sqrtVal
458472 , benchIOSrc1 "joinOuterMap"
459− $ joinMapWith Internal.joinOuterMap halfVal
473+ $ joinMapWith S.joinOuterMap halfVal
460474 , benchIOSrc1 "intersectBy (sqrtVal)"
461− $ joinWith Internal.intersectBy sqrtVal
475+ $ joinWith S.intersectBy sqrtVal
462476 , benchIOSrc1 "intersectBySorted"
463− $ joinMapWith (Internal.intersectBySorted compare) halfVal
477+ $ joinMapWith (S.intersectBySorted compare) halfVal
464478 ]
465479 ]
466480
@@ -482,7 +496,9 @@ benchmarks moduleName size =
482496 [
483497 -- multi-stream
484498 o_1_space_joining size
499+#ifdef USE_PRELUDE
485500 , o_1_space_concatFoldable size
501+#endif
486502 , o_1_space_concat size
487503
488504 , o_1_space_applicative size
benchmark/Streamly/Benchmark/Prelude/Serial/Generation.hs → benchmark/Streamly/Benchmark/Data/Stream/Generate.hsrenamed+72−34
@@ -1,5 +1,5 @@
11-- |
2−-- Module : Serial.Generation
2+-- Module : Stream.Generate
33-- Copyright : (c) 2018 Composewell Technologies
44-- License : BSD-3-Clause
55-- Maintainer : streamly@composewell.com
@@ -9,19 +9,36 @@
99{-# LANGUAGE ScopedTypeVariables #-}
1010{-# LANGUAGE RankNTypes #-}
1111
12−module Serial.Generation (benchmarks) where
12+module Stream.Generate (benchmarks) where
1313
1414import Data.Functor.Identity (Identity)
1515
16−import qualified Prelude
16+import qualified Stream.Common as Common
17+#ifdef USE_PRELUDE
1718import qualified GHC.Exts as GHC
18−
19−import qualified Streamly.Prelude as S
19+import qualified Streamly.Prelude as S
20+import qualified Streamly.Internal.Data.Stream.IsStream as Stream
21+import qualified Prelude
22+#else
23+import qualified Streamly.Internal.Data.Stream as Stream
24+#endif
2025
2126import Gauge
22−import Streamly.Prelude (SerialT, fromSerial, MonadAsync)
2327import Streamly.Benchmark.Common
24−import Streamly.Benchmark.Prelude
28+import Streamly.Internal.Data.Stream.Serial (SerialT)
29+#ifdef USE_PRELUDE
30+import Streamly.Prelude (MonadAsync)
31+import Stream.Common hiding (MonadAsync, replicate, enumerateFromTo)
32+import Streamly.Benchmark.Prelude hiding
33+ (benchIOSrc, sourceUnfoldrM, apDiscardFst, apDiscardSnd, apLiftA2, toNullAp
34+ , monadThen, toNullM, toNullM3, filterAllInM, filterAllOutM, filterSome
35+ , breakAfterSome, toListM, toListSome)
36+#else
37+import Stream.Common
38+#endif
39+
40+import System.IO.Unsafe (unsafeInterleaveIO)
41+
2542import Prelude hiding (repeat, replicate, iterate)
2643
2744-------------------------------------------------------------------------------
@@ -32,6 +49,7 @@ import Prelude hiding (repeat, replicate, iterate)
3249-- fromList
3350-------------------------------------------------------------------------------
3451
52+#ifdef USE_PRELUDE
3553{-# INLINE sourceIsList #-}
3654sourceIsList :: Int -> Int -> SerialT Identity Int
3755sourceIsList value n = GHC.fromList [n..n+value]
@@ -39,6 +57,7 @@ sourceIsList value n = GHC.fromList [n..n+value]
3957{-# INLINE sourceIsString #-}
4058sourceIsString :: Int -> Int -> SerialT Identity Char
4159sourceIsString value n = GHC.fromString (Prelude.replicate (n + value) 'a')
60+#endif
4261
4362{-# INLINE readInstance #-}
4463readInstance :: String -> SerialT Identity Int
@@ -57,6 +76,7 @@ readInstanceList str =
5776 [(x,"")] -> x
5877 _ -> error "readInstance: no parse"
5978
79+#ifdef USE_PRELUDE
6080{-# INLINE repeat #-}
6181repeat :: (Monad m, S.IsStream t) => Int -> Int -> t m Int
6282repeat count = S.take count . S.repeat
@@ -114,41 +134,59 @@ fromIndices value n = S.take value $ S.fromIndices (+ n)
114134{-# INLINE fromIndicesM #-}
115135fromIndicesM :: (MonadAsync m, S.IsStream t) => Int -> Int -> t m Int
116136fromIndicesM value n = S.take value $ S.fromIndicesM (return <$> (+ n))
137+#endif
138+
139+{-# INLINE mfixUnfold #-}
140+mfixUnfold :: Int -> Int -> SerialT IO (Int, Int)
141+mfixUnfold count start = Stream.mfix f
142+ where
143+ f action = do
144+ let incr n act = fmap ((+n) . snd) $ unsafeInterleaveIO act
145+ x <- Common.fromListM [incr 1 action, incr 2 action]
146+ y <- Common.sourceUnfoldr count start
147+ return (x, y)
117148
118149o_1_space_generation :: Int -> [Benchmark]
119150o_1_space_generation value =
120151 [ bgroup "generation"
121− [ benchIOSrc fromSerial "unfoldr" (sourceUnfoldr value)
122− , benchIOSrc fromSerial "unfoldrM" (sourceUnfoldrM value)
123− , benchIOSrc fromSerial "repeat" (repeat value)
124− , benchIOSrc fromSerial "repeatM" (repeatM value)
125− , benchIOSrc fromSerial "replicate" (replicate value)
126− , benchIOSrc fromSerial "replicateM" (replicateM value)
127− , benchIOSrc fromSerial "iterate" (iterate value)
128− , benchIOSrc fromSerial "iterateM" (iterateM value)
129− , benchIOSrc fromSerial "fromIndices" (fromIndices value)
130− , benchIOSrc fromSerial "fromIndicesM" (fromIndicesM value)
131− , benchIOSrc fromSerial "intFromTo" (sourceIntFromTo value)
132− , benchIOSrc fromSerial "intFromThenTo" (sourceIntFromThenTo value)
133− , benchIOSrc fromSerial "integerFromStep" (sourceIntegerFromStep value)
134− , benchIOSrc fromSerial "fracFromThenTo" (sourceFracFromThenTo value)
135− , benchIOSrc fromSerial "fracFromTo" (sourceFracFromTo value)
136− , benchIOSrc fromSerial "fromList" (sourceFromList value)
152+ [ benchIOSrc "unfoldr" (sourceUnfoldr value)
153+ , benchIOSrc "unfoldrM" (sourceUnfoldrM value)
154+#ifdef USE_PRELUDE
155+ , benchIOSrc "repeat" (repeat value)
156+ , benchIOSrc "repeatM" (repeatM value)
157+ , benchIOSrc "replicate" (replicate value)
158+ , benchIOSrc "replicateM" (replicateM value)
159+ , benchIOSrc "iterate" (iterate value)
160+ , benchIOSrc "iterateM" (iterateM value)
161+ , benchIOSrc "fromIndices" (fromIndices value)
162+ , benchIOSrc "fromIndicesM" (fromIndicesM value)
163+ , benchIOSrc "intFromTo" (sourceIntFromTo value)
164+ , benchIOSrc "intFromThenTo" (sourceIntFromThenTo value)
165+ , benchIOSrc "integerFromStep" (sourceIntegerFromStep value)
166+ , benchIOSrc "fracFromThenTo" (sourceFracFromThenTo value)
167+ , benchIOSrc "fracFromTo" (sourceFracFromTo value)
168+ , benchIOSrc "fromList" (sourceFromList value)
137169 , benchPureSrc "IsList.fromList" (sourceIsList value)
138170 , benchPureSrc "IsString.fromString" (sourceIsString value)
139− , benchIOSrc fromSerial "fromListM" (sourceFromListM value)
140− , benchIOSrc fromSerial "enumerateFrom" (enumerateFrom value)
141− , benchIOSrc fromSerial "enumerateFromTo" (enumerateFromTo value)
142− , benchIOSrc fromSerial "enumerateFromThen" (enumerateFromThen value)
143− , benchIOSrc fromSerial "enumerateFromThenTo" (enumerateFromThenTo value)
144− , benchIOSrc fromSerial "enumerate" (enumerate value)
145− , benchIOSrc fromSerial "enumerateTo" (enumerateTo value)
171+ , benchIOSrc "fromListM" (sourceFromListM value)
172+ , benchIOSrc "enumerateFrom" (enumerateFrom value)
173+ , benchIOSrc "enumerateFromTo" (enumerateFromTo value)
174+ , benchIOSrc "enumerateFromThen" (enumerateFromThen value)
175+ , benchIOSrc "enumerateFromThenTo" (enumerateFromThenTo value)
176+ , benchIOSrc "enumerate" (enumerate value)
177+ , benchIOSrc "enumerateTo" (enumerateTo value)
178+#endif
146179
147180 -- These essentially test cons and consM
148− , benchIOSrc fromSerial "fromFoldable" (sourceFromFoldable value)
149− , benchIOSrc fromSerial "fromFoldableM" (sourceFromFoldableM value)
150−
151− , benchIOSrc fromSerial "absTimes" $ absTimes value
181+ , benchIOSrc "fromFoldable" (sourceFromFoldable value)
182+ , benchIOSrc "fromFoldableM" (sourceFromFoldableM value)
183+
184+#ifdef USE_PRELUDE
185+ , benchIOSrc "absTimes" $ absTimes value
186+#endif
187+ , Common.benchIOSrc "mfix_10" (mfixUnfold 10)
188+ , Common.benchIOSrc "mfix_100" (mfixUnfold 100)
189+ , Common.benchIOSrc "mfix_1000" (mfixUnfold 1000)
152190 ]
153191 ]
154192
benchmark/Streamly/Benchmark/Prelude/Serial/Lift.hs → benchmark/Streamly/Benchmark/Data/Stream/Lift.hsrenamed+42−22
@@ -1,5 +1,5 @@
11-- |
2−-- Module : Serial.Lift
2+-- Module : Stream.Lift
33-- Copyright : (c) 2018 Composewell Technologies
44-- License : BSD-3-Clause
55-- Maintainer : streamly@composewell.com
@@ -9,19 +9,30 @@
99{-# LANGUAGE ScopedTypeVariables #-}
1010{-# LANGUAGE RankNTypes #-}
1111
12−module Serial.Lift (benchmarks) where
12+module Stream.Lift (benchmarks) where
1313
14+import Control.DeepSeq (NFData(..))
15+import Control.Monad.Trans.Class (lift)
1416import Control.Monad.State.Strict (StateT, get, put, MonadState)
17+import Data.Functor.Identity (Identity)
18+import Stream.Common (sourceUnfoldr, sourceUnfoldrM, benchIOSrc, drain)
19+import System.Random (randomRIO)
20+#ifdef USE_PRELUDE
21+import Streamly.Benchmark.Prelude hiding
22+ (sourceUnfoldr, sourceUnfoldrM, benchIOSrc)
23+import qualified Streamly.Internal.Data.Stream.IsStream as Stream
24+#else
25+import Streamly.Benchmark.Prelude (benchIO)
26+import qualified Streamly.Internal.Data.Stream as Stream
27+#endif
28+import qualified Streamly.Internal.Data.Fold as Fold
29+import qualified Stream.Common as Common
1530import qualified Control.Monad.State.Strict as State
16−import Control.Monad.Trans.Class (lift)
17−
18−import qualified Streamly.Prelude as S
19−import qualified Streamly.Internal.Data.Stream.IsStream as Internal
2031
2132import Gauge
22−import Streamly.Prelude (SerialT, fromSerial)
33+import Streamly.Internal.Data.Stream.Serial (SerialT)
2334import Streamly.Benchmark.Common
24−import Streamly.Benchmark.Prelude
35+
2536import Prelude hiding (reverse, tail)
2637
2738-------------------------------------------------------------------------------
@@ -29,9 +40,9 @@ import Prelude hiding (reverse, tail)
2940-------------------------------------------------------------------------------
3041
3142{-# INLINE sourceUnfoldrState #-}
32−sourceUnfoldrState :: (S.IsStream t, S.MonadAsync m)
33− => Int -> Int -> t (StateT Int m) Int
34−sourceUnfoldrState value n = S.unfoldrM step n
43+sourceUnfoldrState :: Common.MonadAsync m =>
44+ Int -> Int -> SerialT (StateT Int m) Int
45+sourceUnfoldrState value n = Common.unfoldrM step n
3546 where
3647 step cnt =
3748 if cnt > n + value
@@ -42,27 +53,36 @@ sourceUnfoldrState value n = S.unfoldrM step n
4253 return (Just (s, cnt + 1))
4354
4455{-# INLINE evalStateT #-}
45−evalStateT :: S.MonadAsync m => Int -> Int -> SerialT m Int
56+evalStateT :: Common.MonadAsync m => Int -> Int -> SerialT m Int
4657evalStateT value n =
47− Internal.evalStateT (return 0) (sourceUnfoldrState value n)
58+ Stream.evalStateT (return 0) (sourceUnfoldrState value n)
4859
4960{-# INLINE withState #-}
50−withState :: S.MonadAsync m => Int -> Int -> SerialT m Int
61+withState :: Common.MonadAsync m => Int -> Int -> SerialT m Int
5162withState value n =
52− Internal.evalStateT
53− (return (0 :: Int)) (Internal.liftInner (sourceUnfoldrM value n))
63+ Stream.evalStateT
64+ (return (0 :: Int)) (Stream.liftInner (sourceUnfoldrM value n))
65+
66+{-# INLINE benchHoistSink #-}
67+benchHoistSink
68+ :: (NFData b)
69+ => Int -> String -> (SerialT Identity Int -> IO b) -> Benchmark
70+benchHoistSink value name f =
71+ bench name $ nfIO $ randomRIO (1,1) >>= f . sourceUnfoldr value
5472
5573o_1_space_hoisting :: Int -> [Benchmark]
5674o_1_space_hoisting value =
5775 [ bgroup "hoisting"
58− [ benchIOSrc fromSerial "evalState" (evalStateT value)
59− , benchIOSrc fromSerial "withState" (withState value)
76+ [ benchIOSrc "evalState" (evalStateT value)
77+ , benchIOSrc "withState" (withState value)
78+ , benchHoistSink value "generally"
79+ ((\xs -> Stream.fold Fold.length xs :: IO Int) . Stream.generally)
6080 ]
6181 ]
6282
6383{-# INLINE iterateStateIO #-}
6484iterateStateIO ::
65− (S.MonadAsync m)
85+ Monad m
6686 => Int
6787 -> StateT Int m Int
6888iterateStateIO n = do
@@ -86,7 +106,7 @@ iterateStateT n = do
86106{-# INLINE iterateState #-}
87107{-# SPECIALIZE iterateState :: Int -> SerialT (StateT Int IO) Int #-}
88108iterateState ::
89− (S.MonadAsync m, MonadState Int m)
109+ MonadState Int m
90110 => Int
91111 -> SerialT m Int
92112iterateState n = do
@@ -103,9 +123,9 @@ o_n_heap_transformer value =
103123 [ benchIO "StateT Int IO (n times) (baseline)" $ \n ->
104124 State.evalStateT (iterateStateIO n) value
105125 , benchIO "SerialT (StateT Int IO) (n times)" $ \n ->
106− State.evalStateT (S.drain (iterateStateT n)) value
126+ State.evalStateT (drain (iterateStateT n)) value
107127 , benchIO "MonadState Int m => SerialT m Int" $ \n ->
108− State.evalStateT (S.drain (iterateState n)) value
128+ State.evalStateT (drain (iterateState n)) value
109129 ]
110130 ]
111131
benchmark/Streamly/Benchmark/Prelude/Serial/NestedFold.hs → benchmark/Streamly/Benchmark/Data/Stream/Reduce.hsrenamed+137−86
@@ -1,5 +1,5 @@
11-- |
2−-- Module : Serial.NestedFold
2+-- Module : Stream.Reduce
33-- Copyright : (c) 2018 Composewell Technologies
44-- License : BSD-3-Clause
55-- Maintainer : streamly@composewell.com
@@ -11,26 +11,37 @@
1111{-# LANGUAGE DeriveGeneric #-}
1212{-# LANGUAGE RankNTypes #-}
1313
14−module Serial.NestedFold (benchmarks) where
14+module Stream.Reduce (benchmarks) where
1515
1616import Control.DeepSeq (NFData(..))
17−import Control.Monad (when)
1817import Control.Monad.IO.Class (MonadIO(..))
1918import Data.Monoid (Sum(..))
20−import Data.Proxy (Proxy(..))
21−import Data.HashMap.Strict (HashMap)
2219import GHC.Generics (Generic)
2320import Streamly.Internal.Data.IsMap.HashMap ()
21+import Streamly.Internal.Data.Stream.Serial (SerialT)
2422
2523import qualified Streamly.Internal.Data.Refold.Type as Refold
2624import qualified Streamly.Internal.Data.Fold as FL
27−import qualified Streamly.Internal.Data.Stream.IsStream as Internal
28−import qualified Streamly.Prelude as S
25+import qualified Stream.Common as Common
26+#ifdef USE_PRELUDE
27+import Control.Monad (when)
28+import Data.Proxy (Proxy(..))
29+import Data.HashMap.Strict (HashMap)
30+import qualified Streamly.Internal.Data.Stream.IsStream as S
31+import Streamly.Prelude (fromSerial)
32+import Streamly.Benchmark.Prelude hiding
33+ ( benchIOSrc, sourceUnfoldrM, apDiscardFst, apDiscardSnd, apLiftA2
34+ , toNullAp, monadThen, toNullM, toNullM3, filterAllInM, filterAllOutM
35+ , filterSome, breakAfterSome, toListM, toListSome, transformMapM
36+ , transformComposeMapM, transformTeeMapM, transformZipMapM)
37+#else
38+import Streamly.Benchmark.Prelude (benchIO)
39+import qualified Streamly.Internal.Data.Stream as S
40+#endif
2941
3042import Gauge
31−import Streamly.Prelude (SerialT, fromSerial)
3243import Streamly.Benchmark.Common
33−import Streamly.Benchmark.Prelude
44+import Stream.Common
3445import Prelude hiding (reverse, tail)
3546
3647-------------------------------------------------------------------------------
@@ -48,13 +59,14 @@ iterateN g initial count = f count initial
4859
4960-- Iterate a transformation over a singleton stream
5061{-# INLINE iterateSingleton #-}
51−iterateSingleton :: S.MonadAsync m
62+iterateSingleton :: Monad m
5263 => (Int -> SerialT m Int -> SerialT m Int)
5364 -> Int
5465 -> Int
5566 -> SerialT m Int
5667iterateSingleton g count n = iterateN g (return n) count
5768
69+{-
5870-- XXX need to check why this is slower than the explicit recursion above, even
5971-- if the above code is written in a foldr like head recursive way. We also
6072-- need to try this with foldlM' once #150 is fixed.
@@ -62,17 +74,18 @@ iterateSingleton g count n = iterateN g (return n) count
6274-- foldrM and any related fusion issues.
6375{-# INLINE _iterateSingleton #-}
6476_iterateSingleton ::
65− S.MonadAsync m
77+ Monad m
6678 => (Int -> SerialT m Int -> SerialT m Int)
6779 -> Int
6880 -> Int
6981 -> SerialT m Int
7082_iterateSingleton g value n = S.foldrM g (return n) $ sourceIntFromTo value n
83+-}
7184
7285-- Apply transformation g count times on a stream of length len
7386{-# INLINE iterateSource #-}
7487iterateSource ::
75− S.MonadAsync m
88+ MonadAsync m
7689 => (SerialT m Int -> SerialT m Int)
7790 -> Int
7891 -> Int
@@ -94,9 +107,9 @@ o_n_space_functor value =
94107 [ bgroup "Functor"
95108 [ benchIO "(+) (n times) (baseline)" $ \i0 ->
96109 iterateN (\i acc -> acc >>= \n -> return $ i + n) (return i0) value
97− , benchIOSrc fromSerial "(<$) (n times)" $
110+ , benchIOSrc "(<$) (n times)" $
98111 iterateSingleton (<$) value
99− , benchIOSrc fromSerial "fmap (n times)" $
112+ , benchIOSrc "fmap (n times)" $
100113 iterateSingleton (fmap . (+)) value
101114 {-
102115 , benchIOSrc fromSerial "_(<$) (n times)" $
@@ -111,74 +124,92 @@ o_n_space_functor value =
111124-- Grouping transformations
112125-------------------------------------------------------------------------------
113126
127+#ifdef USE_PRELUDE
114128{-# INLINE groups #-}
115129groups :: MonadIO m => SerialT m Int -> m ()
116−groups = S.drain . S.groups FL.drain
130+groups = Common.drain . S.groups FL.drain
117131
118132-- XXX Change this test when the order of comparison is later changed
119133{-# INLINE groupsByGT #-}
120134groupsByGT :: MonadIO m => SerialT m Int -> m ()
121−groupsByGT = S.drain . S.groupsBy (>) FL.drain
135+groupsByGT = Common.drain . S.groupsBy (>) FL.drain
122136
123137{-# INLINE groupsByEq #-}
124138groupsByEq :: MonadIO m => SerialT m Int -> m ()
125−groupsByEq = S.drain . S.groupsBy (==) FL.drain
139+groupsByEq = Common.drain . S.groupsBy (==) FL.drain
126140
127141-- XXX Change this test when the order of comparison is later changed
128142{-# INLINE groupsByRollingLT #-}
129143groupsByRollingLT :: MonadIO m => SerialT m Int -> m ()
130144groupsByRollingLT =
131− S.drain . S.groupsByRolling (<) FL.drain
145+ Common.drain . S.groupsByRolling (<) FL.drain
132146
133147{-# INLINE groupsByRollingEq #-}
134148groupsByRollingEq :: MonadIO m => SerialT m Int -> m ()
135149groupsByRollingEq =
136− S.drain . S.groupsByRolling (==) FL.drain
150+ Common.drain . S.groupsByRolling (==) FL.drain
151+#endif
137152
138153{-# INLINE foldMany #-}
139154foldMany :: Monad m => SerialT m Int -> m ()
140155foldMany =
141− S.drain
142− . S.map getSum
143− . Internal.foldMany (FL.take 2 FL.mconcat)
144− . S.map Sum
156+ Common.drain
157+ . fmap getSum
158+ . S.foldMany (FL.take 2 FL.mconcat)
159+ . fmap Sum
160+
161+{-# INLINE foldManyPost #-}
162+foldManyPost :: Monad m => SerialT m Int -> m ()
163+foldManyPost =
164+ Common.drain
165+ . fmap getSum
166+ . S.foldManyPost (FL.take 2 FL.mconcat)
167+ . fmap Sum
145168
146169{-# INLINE refoldMany #-}
147170refoldMany :: Monad m => SerialT m Int -> m ()
148171refoldMany =
149− S.drain
150− . S.map getSum
151− . Internal.refoldMany (Refold.take 2 Refold.sconcat) (return mempty)
152− . S.map Sum
172+ Common.drain
173+ . fmap getSum
174+ . S.refoldMany (Refold.take 2 Refold.sconcat) (return mempty)
175+ . fmap Sum
153176
154177{-# INLINE foldIterateM #-}
155178foldIterateM :: Monad m => SerialT m Int -> m ()
156179foldIterateM =
157− S.drain
158− . S.map getSum
159− . Internal.foldIterateM
180+ Common.drain
181+ . fmap getSum
182+ . S.foldIterateM
160183 (return . FL.take 2 . FL.sconcat) (return (Sum 0))
161− . S.map Sum
184+ . fmap Sum
162185
163186{-# INLINE refoldIterateM #-}
164187refoldIterateM :: Monad m => SerialT m Int -> m ()
165188refoldIterateM =
166− S.drain
167− . S.map getSum
168− . Internal.refoldIterateM
189+ Common.drain
190+ . fmap getSum
191+ . S.refoldIterateM
169192 (Refold.take 2 Refold.sconcat) (return (Sum 0))
170− . S.map Sum
193+ . fmap Sum
171194
172195o_1_space_grouping :: Int -> [Benchmark]
173196o_1_space_grouping value =
174197 -- Buffering operations using heap proportional to group/window sizes.
175198 [ bgroup "grouping"
176− [ benchIOSink value "groups" groups
199+ [
200+#ifdef USE_PRELUDE
201+ benchIOSink value "groups" groups
177202 , benchIOSink value "groupsByGT" groupsByGT
178203 , benchIOSink value "groupsByEq" groupsByEq
179204 , benchIOSink value "groupsByRollingLT" groupsByRollingLT
180205 , benchIOSink value "groupsByRollingEq" groupsByRollingEq
181− , benchIOSink value "foldMany" foldMany
206+ ,
207+#endif
208+ -- XXX parseMany/parseIterate benchmarks are in the Parser/ParserD
209+ -- modules we can bring those here. arraysOf benchmarks are in
210+ -- Parser/ParserD/Array.Stream/FileSystem.Handle.
211+ benchIOSink value "foldMany" foldMany
212+ , benchIOSink value "foldManyPost" foldManyPost
182213 , benchIOSink value "refoldMany" refoldMany
183214 , benchIOSink value "foldIterateM" foldIterateM
184215 , benchIOSink value "refoldIterateM" refoldIterateM
@@ -195,7 +226,7 @@ reverse n = composeN n S.reverse
195226
196227{-# INLINE reverse' #-}
197228reverse' :: MonadIO m => Int -> SerialT m Int -> m ()
198−reverse' n = composeN n Internal.reverse'
229+reverse' n = composeN n S.reverse'
199230
200231o_n_heap_buffering :: Int -> [Benchmark]
201232o_n_heap_buffering value =
@@ -205,7 +236,9 @@ o_n_heap_buffering value =
205236 benchIOSink value "reverse" (reverse 1)
206237 , benchIOSink value "reverse'" (reverse' 1)
207238
239+#ifdef USE_PRELUDE
208240 , benchIOSink value "mkAsync" (mkAsync fromSerial)
241+#endif
209242 ]
210243 ]
211244
@@ -213,25 +246,26 @@ o_n_heap_buffering value =
213246-- Grouping/Splitting
214247-------------------------------------------------------------------------------
215248
249+#ifdef USE_PRELUDE
216250{-# INLINE classifySessionsOf #-}
217−classifySessionsOf :: S.MonadAsync m => (Int -> Int) -> SerialT m Int -> m ()
251+classifySessionsOf :: MonadAsync m => (Int -> Int) -> SerialT m Int -> m ()
218252classifySessionsOf getKey =
219− S.drain
220− . Internal.classifySessionsOf
253+ Common.drain
254+ . S.classifySessionsOf
221255 (const (return False)) 3 (FL.take 10 FL.sum)
222− . Internal.timestamped
223− . S.map (\x -> (getKey x, x))
256+ . S.timestamped
257+ . fmap (\x -> (getKey x, x))
224258
225259{-# INLINE classifySessionsOfHash #-}
226−classifySessionsOfHash :: S.MonadAsync m =>
260+classifySessionsOfHash :: MonadAsync m =>
227261 (Int -> Int) -> SerialT m Int -> m ()
228262classifySessionsOfHash getKey =
229− S.drain
230− . Internal.classifySessionsByGeneric
263+ Common.drain
264+ . S.classifySessionsByGeneric
231265 (Proxy :: Proxy (HashMap k))
232266 1 False (const (return False)) 3 (FL.take 10 FL.sum)
233− . Internal.timestamped
234− . S.map (\x -> (getKey x, x))
267+ . S.timestamped
268+ . fmap (\x -> (getKey x, x))
235269
236270o_n_space_grouping :: Int -> [Benchmark]
237271o_n_space_grouping value =
@@ -251,6 +285,7 @@ o_n_space_grouping value =
251285 where
252286
253287 getKey n = (`mod` n)
288+#endif
254289
255290-------------------------------------------------------------------------------
256291-- Mixed Transformation
@@ -258,15 +293,15 @@ o_n_space_grouping value =
258293
259294{-# INLINE scanMap #-}
260295scanMap :: MonadIO m => Int -> SerialT m Int -> m ()
261−scanMap n = composeN n $ S.map (subtract 1) . S.scanl' (+) 0
296+scanMap n = composeN n $ fmap (subtract 1) . Common.scanl' (+) 0
262297
263298{-# INLINE dropMap #-}
264299dropMap :: MonadIO m => Int -> SerialT m Int -> m ()
265−dropMap n = composeN n $ S.map (subtract 1) . S.drop 1
300+dropMap n = composeN n $ fmap (subtract 1) . S.drop 1
266301
267302{-# INLINE dropScan #-}
268303dropScan :: MonadIO m => Int -> SerialT m Int -> m ()
269−dropScan n = composeN n $ S.scanl' (+) 0 . S.drop 1
304+dropScan n = composeN n $ Common.scanl' (+) 0 . S.drop 1
270305
271306{-# INLINE takeDrop #-}
272307takeDrop :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
@@ -274,11 +309,11 @@ takeDrop value n = composeN n $ S.drop 1 . S.take (value + 1)
274309
275310{-# INLINE takeScan #-}
276311takeScan :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
277−takeScan value n = composeN n $ S.scanl' (+) 0 . S.take (value + 1)
312+takeScan value n = composeN n $ Common.scanl' (+) 0 . S.take (value + 1)
278313
279314{-# INLINE takeMap #-}
280315takeMap :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
281−takeMap value n = composeN n $ S.map (subtract 1) . S.take (value + 1)
316+takeMap value n = composeN n $ fmap (subtract 1) . S.take (value + 1)
282317
283318{-# INLINE filterDrop #-}
284319filterDrop :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
@@ -290,15 +325,17 @@ filterTake value n = composeN n $ S.take (value + 1) . S.filter (<= (value + 1))
290325
291326{-# INLINE filterScan #-}
292327filterScan :: MonadIO m => Int -> SerialT m Int -> m ()
293−filterScan n = composeN n $ S.scanl' (+) 0 . S.filter (<= maxBound)
328+filterScan n = composeN n $ Common.scanl' (+) 0 . S.filter (<= maxBound)
294329
330+#ifdef USE_PRELUDE
295331{-# INLINE filterScanl1 #-}
296332filterScanl1 :: MonadIO m => Int -> SerialT m Int -> m ()
297333filterScanl1 n = composeN n $ S.scanl1' (+) . S.filter (<= maxBound)
334+#endif
298335
299336{-# INLINE filterMap #-}
300337filterMap :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
301−filterMap value n = composeN n $ S.map (subtract 1) . S.filter (<= (value + 1))
338+filterMap value n = composeN n $ fmap (subtract 1) . S.filter (<= (value + 1))
302339
303340-------------------------------------------------------------------------------
304341-- Scan and fold
@@ -310,17 +347,17 @@ data Pair a b =
310347
311348{-# INLINE sumProductFold #-}
312349sumProductFold :: Monad m => SerialT m Int -> m (Int, Int)
313−sumProductFold = S.foldl' (\(s, p) x -> (s + x, p * x)) (0, 1)
350+sumProductFold = Common.foldl' (\(s, p) x -> (s + x, p * x)) (0, 1)
314351
315352{-# INLINE sumProductScan #-}
316353sumProductScan :: Monad m => SerialT m Int -> m (Pair Int Int)
317354sumProductScan =
318− S.foldl' (\(Pair _ p) (s0, x) -> Pair s0 (p * x)) (Pair 0 1) .
319− S.scanl' (\(s, _) x -> (s + x, x)) (0, 0)
355+ Common.foldl' (\(Pair _ p) (s0, x) -> Pair s0 (p * x)) (Pair 0 1) .
356+ Common.scanl' (\(s, _) x -> (s + x, x)) (0, 0)
320357
321358{-# INLINE foldl'ReduceMap #-}
322359foldl'ReduceMap :: Monad m => SerialT m Int -> m Int
323−foldl'ReduceMap = fmap (+ 1) . S.foldl' (+) 0
360+foldl'ReduceMap = fmap (+ 1) . Common.foldl' (+) 0
324361
325362o_1_space_transformations_mixed :: Int -> [Benchmark]
326363o_1_space_transformations_mixed value =
@@ -347,7 +384,9 @@ o_1_space_transformations_mixedX4 value =
347384 , benchIOSink value "filter-drop" (filterDrop value 4)
348385 , benchIOSink value "filter-take" (filterTake value 4)
349386 , benchIOSink value "filter-scan" (filterScan 4)
387+#ifdef USE_PRELUDE
350388 , benchIOSink value "filter-scanl1" (filterScanl1 4)
389+#endif
351390 , benchIOSink value "filter-map" (filterMap value 4)
352391 ]
353392 ]
@@ -358,40 +397,43 @@ o_1_space_transformations_mixedX4 value =
358397
359398-- this is quadratic
360399{-# INLINE iterateScan #-}
361−iterateScan :: S.MonadAsync m => Int -> Int -> Int -> SerialT m Int
362−iterateScan = iterateSource (S.scanl' (+) 0)
400+iterateScan :: MonadAsync m => Int -> Int -> Int -> SerialT m Int
401+iterateScan = iterateSource (Common.scanl' (+) 0)
363402
403+#ifdef USE_PRELUDE
364404-- this is quadratic
365405{-# INLINE iterateScanl1 #-}
366−iterateScanl1 :: S.MonadAsync m => Int -> Int -> Int -> SerialT m Int
406+iterateScanl1 :: MonadAsync m => Int -> Int -> Int -> SerialT m Int
367407iterateScanl1 = iterateSource (S.scanl1' (+))
408+#endif
368409
369410{-# INLINE iterateMapM #-}
370−iterateMapM :: S.MonadAsync m => Int -> Int -> Int -> SerialT m Int
411+iterateMapM :: MonadAsync m => Int -> Int -> Int -> SerialT m Int
371412iterateMapM = iterateSource (S.mapM return)
372413
373414{-# INLINE iterateFilterEven #-}
374−iterateFilterEven :: S.MonadAsync m => Int -> Int -> Int -> SerialT m Int
415+iterateFilterEven :: MonadAsync m => Int -> Int -> Int -> SerialT m Int
375416iterateFilterEven = iterateSource (S.filter even)
376417
377418{-# INLINE iterateTakeAll #-}
378−iterateTakeAll :: S.MonadAsync m => Int -> Int -> Int -> Int -> SerialT m Int
419+iterateTakeAll :: MonadAsync m => Int -> Int -> Int -> Int -> SerialT m Int
379420iterateTakeAll value = iterateSource (S.take (value + 1))
380421
381422{-# INLINE iterateDropOne #-}
382−iterateDropOne :: S.MonadAsync m => Int -> Int -> Int -> SerialT m Int
423+iterateDropOne :: MonadAsync m => Int -> Int -> Int -> SerialT m Int
383424iterateDropOne = iterateSource (S.drop 1)
384425
385426{-# INLINE iterateDropWhileFalse #-}
386−iterateDropWhileFalse :: S.MonadAsync m
427+iterateDropWhileFalse :: MonadAsync m
387428 => Int -> Int -> Int -> Int -> SerialT m Int
388429iterateDropWhileFalse value = iterateSource (S.dropWhile (> (value + 1)))
389430
390431{-# INLINE iterateDropWhileTrue #-}
391−iterateDropWhileTrue :: S.MonadAsync m
432+iterateDropWhileTrue :: MonadAsync m
392433 => Int -> Int -> Int -> Int -> SerialT m Int
393434iterateDropWhileTrue value = iterateSource (S.dropWhile (<= (value + 1)))
394435
436+#ifdef USE_PRELUDE
395437{-# INLINE tail #-}
396438tail :: Monad m => SerialT m a -> m ()
397439tail s = S.tail s >>= mapM_ tail
@@ -403,26 +445,31 @@ nullHeadTail s = do
403445 when (not r) $ do
404446 _ <- S.head s
405447 S.tail s >>= mapM_ nullHeadTail
448+#endif
406449
407450-- Head recursive operations.
408451o_n_stack_iterated :: Int -> [Benchmark]
409452o_n_stack_iterated value = by10 `seq` by100 `seq`
410453 [ bgroup "iterated"
411− [ benchIOSrc fromSerial "mapM (n/10 x 10)" $ iterateMapM by10 10
412− , benchIOSrc fromSerial "scanl' (quadratic) (n/100 x 100)" $
454+ [ benchIOSrc "mapM (n/10 x 10)" $ iterateMapM by10 10
455+ , benchIOSrc "scanl' (quadratic) (n/100 x 100)" $
413456 iterateScan by100 100
414− , benchIOSrc fromSerial "scanl1' (n/10 x 10)" $ iterateScanl1 by10 10
415− , benchIOSrc fromSerial "filterEven (n/10 x 10)" $
457+#ifdef USE_PRELUDE
458+ , benchIOSrc "scanl1' (n/10 x 10)" $ iterateScanl1 by10 10
459+#endif
460+ , benchIOSrc "filterEven (n/10 x 10)" $
416461 iterateFilterEven by10 10
417− , benchIOSrc fromSerial "takeAll (n/10 x 10)" $
462+ , benchIOSrc "takeAll (n/10 x 10)" $
418463 iterateTakeAll value by10 10
419− , benchIOSrc fromSerial "dropOne (n/10 x 10)" $ iterateDropOne by10 10
420− , benchIOSrc fromSerial "dropWhileFalse (n/10 x 10)" $
464+ , benchIOSrc "dropOne (n/10 x 10)" $ iterateDropOne by10 10
465+ , benchIOSrc "dropWhileFalse (n/10 x 10)" $
421466 iterateDropWhileFalse value by10 10
422− , benchIOSrc fromSerial "dropWhileTrue (n/10 x 10)" $
467+ , benchIOSrc "dropWhileTrue (n/10 x 10)" $
423468 iterateDropWhileTrue value by10 10
469+#ifdef USE_PRELUDE
424470 , benchIOSink value "tail" tail
425471 , benchIOSink value "nullHeadTail" nullHeadTail
472+#endif
426473 ]
427474 ]
428475
@@ -438,12 +485,12 @@ o_n_stack_iterated value = by10 `seq` by100 `seq`
438485o_1_space_pipes :: Int -> [Benchmark]
439486o_1_space_pipes value =
440487 [ bgroup "pipes"
441− [ benchIOSink value "mapM" (transformMapM fromSerial 1)
442− , benchIOSink value "compose" (transformComposeMapM fromSerial 1)
443− , benchIOSink value "tee" (transformTeeMapM fromSerial 1)
488+ [ benchIOSink value "mapM" (transformMapM 1)
489+ , benchIOSink value "compose" (transformComposeMapM 1)
490+ , benchIOSink value "tee" (transformTeeMapM 1)
444491#ifdef DEVBUILD
445492 -- XXX this take 1 GB memory to compile
446− , benchIOSink value "zip" (transformZipMapM fromSerial 1)
493+ , benchIOSink value "zip" (transformZipMapM 1)
447494#endif
448495 ]
449496 ]
@@ -451,12 +498,12 @@ o_1_space_pipes value =
451498o_1_space_pipesX4 :: Int -> [Benchmark]
452499o_1_space_pipesX4 value =
453500 [ bgroup "pipesX4"
454− [ benchIOSink value "mapM" (transformMapM fromSerial 4)
455− , benchIOSink value "compose" (transformComposeMapM fromSerial 4)
456− , benchIOSink value "tee" (transformTeeMapM fromSerial 4)
501+ [ benchIOSink value "mapM" (transformMapM 4)
502+ , benchIOSink value "compose" (transformComposeMapM 4)
503+ , benchIOSink value "tee" (transformTeeMapM 4)
457504#ifdef DEVBUILD
458505 -- XXX this take 1 GB memory to compile
459− , benchIOSink value "zip" (transformZipMapM fromSerial 4)
506+ , benchIOSink value "zip" (transformZipMapM 4)
460507#endif
461508 ]
462509 ]
@@ -481,8 +528,12 @@ benchmarks moduleName size =
481528 ]
482529 , bgroup (o_n_stack_prefix moduleName) (o_n_stack_iterated size)
483530 , bgroup (o_n_heap_prefix moduleName) $ Prelude.concat
484− [ o_n_space_grouping size
485− , o_n_space_functor size
531+ [
532+#ifdef USE_PRELUDE
533+ o_n_space_grouping size
534+ ,
535+#endif
536+ o_n_space_functor size
486537 , o_n_heap_buffering size
487538 ]
488539 ]
benchmark/Streamly/Benchmark/Prelude/Serial/Split.hs → benchmark/Streamly/Benchmark/Data/Stream/Split.hsrenamed+2−2
@@ -1,5 +1,5 @@
11-- |
2−-- Module : Streamly.Benchmark.Prelude.Serial.Split
2+-- Module : Stream.Split
33-- Copyright : (c) 2019 Composewell Technologies
44-- License : BSD-3-Clause
55-- Maintainer : streamly@composewell.com
@@ -18,7 +18,7 @@
1818{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
1919#endif
2020
21−module Serial.Split (benchmarks) where
21+module Stream.Split (benchmarks) where
2222
2323import Data.Char (ord)
2424import Data.Word (Word8)
benchmark/Streamly/Benchmark/Prelude/Serial/Transformation.hs → benchmark/Streamly/Benchmark/Data/Stream/Transform.hsrenamed+108−100
@@ -1,5 +1,5 @@
11-- |
2−-- Module : Serial.Transformation
2+-- Module : Stream.Transform
33-- Copyright : (c) 2018 Composewell Technologies
44-- License : BSD-3-Clause
55-- Maintainer : streamly@composewell.com
@@ -18,30 +18,37 @@
1818{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
1919#endif
2020
21−module Serial.Transformation (benchmarks) where
21+module Stream.Transform (benchmarks) where
2222
2323import Control.DeepSeq (NFData(..))
2424import Control.Monad.IO.Class (MonadIO(..))
2525import Data.Functor.Identity (Identity)
26−import System.Random (randomRIO)
2726
28−#ifdef INSPECTION
29−import Test.Inspection
30−#endif
27+import System.Random (randomRIO)
3128
32−import qualified Streamly.Prelude as S
33−import qualified Streamly.Internal.Data.Stream as Stream
34−import qualified Streamly.Internal.Data.Stream.IsStream as Internal
3529import qualified Streamly.Internal.Data.Fold as FL
36−import qualified Streamly.Internal.Data.Unfold as Unfold
30+
3731import qualified Prelude
32+import qualified Stream.Common as Common
33+import qualified Streamly.Internal.Data.Unfold as Unfold
34+#ifdef USE_PRELUDE
35+import Streamly.Benchmark.Prelude hiding
36+ ( benchIOSrc, sourceUnfoldrM, apDiscardFst, apDiscardSnd, apLiftA2, toNullAp
37+ , monadThen, toNullM, toNullM3, filterAllInM, filterAllOutM, filterSome
38+ , breakAfterSome, toListM, toListSome, transformMapM, transformComposeMapM
39+ , transformTeeMapM, transformZipMapM, mapN, mapM)
40+import qualified Streamly.Internal.Data.Stream.IsStream as Stream
41+import Streamly.Internal.Data.Time.Units
42+#else
43+import Streamly.Benchmark.Prelude (benchIO)
44+import qualified Streamly.Internal.Data.Stream as Stream
45+#endif
3846
3947import Gauge
40−import Streamly.Prelude (SerialT, fromSerial, MonadAsync)
48+import Streamly.Internal.Data.Stream.Serial (SerialT)
49+import Stream.Common hiding (scanl')
4150import Streamly.Benchmark.Common
42−import Streamly.Benchmark.Prelude
43−import Streamly.Internal.Data.Time.Units
44−import Prelude hiding (sequence, mapM, fmap)
51+import Prelude hiding (sequence, mapM)
4552
4653-------------------------------------------------------------------------------
4754-- Pipelines (stream-to-stream transformations)
@@ -94,83 +101,84 @@ o_n_space_traversable value =
94101-- maps and scans
95102-------------------------------------------------------------------------------
96103
104+#ifdef USE_PRELUDE
97105{-# INLINE scanl' #-}
98106scanl' :: MonadIO m => Int -> SerialT m Int -> m ()
99−scanl' n = composeN n $ S.scanl' (+) 0
107+scanl' n = composeN n $ Stream.scanl' (+) 0
100108
101109{-# INLINE scanlM' #-}
102110scanlM' :: MonadIO m => Int -> SerialT m Int -> m ()
103−scanlM' n = composeN n $ S.scanlM' (\b a -> return $ b + a) (return 0)
111+scanlM' n = composeN n $ Stream.scanlM' (\b a -> return $ b + a) (return 0)
104112
105113{-# INLINE scanl1' #-}
106114scanl1' :: MonadIO m => Int -> SerialT m Int -> m ()
107−scanl1' n = composeN n $ S.scanl1' (+)
115+scanl1' n = composeN n $ Stream.scanl1' (+)
108116
109117{-# INLINE scanl1M' #-}
110118scanl1M' :: MonadIO m => Int -> SerialT m Int -> m ()
111−scanl1M' n = composeN n $ S.scanl1M' (\b a -> return $ b + a)
119+scanl1M' n = composeN n $ Stream.scanl1M' (\b a -> return $ b + a)
120+#endif
112121
113122{-# INLINE scan #-}
114123scan :: MonadIO m => Int -> SerialT m Int -> m ()
115−scan n = composeN n $ S.scan FL.sum
124+scan n = composeN n $ Stream.scan FL.sum
116125
126+#ifdef USE_PRELUDE
117127{-# INLINE postscanl' #-}
118128postscanl' :: MonadIO m => Int -> SerialT m Int -> m ()
119−postscanl' n = composeN n $ S.postscanl' (+) 0
129+postscanl' n = composeN n $ Stream.postscanl' (+) 0
120130
121131{-# INLINE postscanlM' #-}
122132postscanlM' :: MonadIO m => Int -> SerialT m Int -> m ()
123−postscanlM' n = composeN n $ S.postscanlM' (\b a -> return $ b + a) (return 0)
133+postscanlM' n = composeN n $ Stream.postscanlM' (\b a -> return $ b + a) (return 0)
134+#endif
124135
125136{-# INLINE postscan #-}
126137postscan :: MonadIO m => Int -> SerialT m Int -> m ()
127−postscan n = composeN n $ S.postscan FL.sum
138+postscan n = composeN n $ Stream.postscan FL.sum
128139
129140{-# INLINE sequence #-}
130−sequence ::
131− (S.IsStream t, S.MonadAsync m)
132− => (t m Int -> S.SerialT m Int)
133− -> t m (m Int)
134− -> m ()
135−sequence t = S.drain . t . S.sequence
141+sequence :: MonadAsync m => SerialT m (m Int) -> m ()
142+sequence = Common.drain . Stream.sequence
136143
137144{-# INLINE tap #-}
138145tap :: MonadIO m => Int -> SerialT m Int -> m ()
139−tap n = composeN n $ S.tap FL.sum
146+tap n = composeN n $ Stream.tap FL.sum
140147
148+#ifdef USE_PRELUDE
141149{-# INLINE pollCounts #-}
142150pollCounts :: Int -> SerialT IO Int -> IO ()
143151pollCounts n =
144− composeN n (Internal.pollCounts (const True) f)
152+ composeN n (Stream.pollCounts (const True) f)
145153
146154 where
147155
148− f = S.drain . Internal.rollingMap2 (-) . Internal.delayPost 1
156+ f = Stream.drain . Stream.rollingMap2 (-) . Stream.delayPost 1
149157
150158{-# INLINE timestamped #-}
151−timestamped :: (S.MonadAsync m) => SerialT m Int -> m ()
152−timestamped = S.drain . Internal.timestamped
159+timestamped :: (MonadAsync m) => SerialT m Int -> m ()
160+timestamped = Stream.drain . Stream.timestamped
161+#endif
153162
154163{-# INLINE foldrS #-}
155164foldrS :: MonadIO m => Int -> SerialT m Int -> m ()
156−foldrS n = composeN n $ Internal.foldrS S.cons S.nil
165+foldrS n = composeN n $ Stream.foldrS Stream.cons Stream.nil
157166
158167{-# INLINE foldrSMap #-}
159168foldrSMap :: MonadIO m => Int -> SerialT m Int -> m ()
160−foldrSMap n = composeN n $ Internal.foldrS (\x xs -> x + 1 `S.cons` xs) S.nil
169+foldrSMap n = composeN n $ Stream.foldrS (\x xs -> x + 1 `Stream.cons` xs) Stream.nil
161170
162171{-# INLINE foldrT #-}
163172foldrT :: MonadIO m => Int -> SerialT m Int -> m ()
164−foldrT n = composeN n $ Internal.foldrT S.cons S.nil
173+foldrT n = composeN n $ Stream.foldrT Stream.cons Stream.nil
165174
166175{-# INLINE foldrTMap #-}
167176foldrTMap :: MonadIO m => Int -> SerialT m Int -> m ()
168−foldrTMap n = composeN n $ Internal.foldrT (\x xs -> x + 1 `S.cons` xs) S.nil
169−
177+foldrTMap n = composeN n $ Stream.foldrT (\x xs -> x + 1 `Stream.cons` xs) Stream.nil
170178
171179{-# INLINE trace #-}
172180trace :: MonadAsync m => Int -> SerialT m Int -> m ()
173−trace n = composeN n $ Internal.trace return
181+trace n = composeN n $ Stream.trace return
174182
175183o_1_space_mapping :: Int -> [Benchmark]
176184o_1_space_mapping value =
@@ -184,11 +192,12 @@ o_1_space_mapping value =
184192 , benchIOSink value "foldrTMap" (foldrTMap 1)
185193
186194 -- Mapping
187− , benchIOSink value "map" (mapN fromSerial 1)
195+ , benchIOSink value "map" (mapN 1)
188196 , bench "sequence" $ nfIO $ randomRIO (1, 1000) >>= \n ->
189− sequence fromSerial (sourceUnfoldrAction value n)
190− , benchIOSink value "mapM" (mapM fromSerial 1)
197+ sequence (sourceUnfoldrAction value n)
198+ , benchIOSink value "mapM" (mapM 1)
191199 , benchIOSink value "tap" (tap 1)
200+#ifdef USE_PRELUDE
192201 , benchIOSink value "pollCounts 1 second" (pollCounts 1)
193202 , benchIOSink value "timestamped" timestamped
194203
@@ -199,7 +208,7 @@ o_1_space_mapping value =
199208 , benchIOSink value "scanl1M'" (scanl1M' 1)
200209 , benchIOSink value "postscanl'" (postscanl' 1)
201210 , benchIOSink value "postscanlM'" (postscanlM' 1)
202−
211+#endif
203212 , benchIOSink value "scan" (scan 1)
204213 , benchIOSink value "postscan" (postscan 1)
205214 ]
@@ -208,36 +217,37 @@ o_1_space_mapping value =
208217o_1_space_mappingX4 :: Int -> [Benchmark]
209218o_1_space_mappingX4 value =
210219 [ bgroup "mappingX4"
211− [ benchIOSink value "map" (mapN fromSerial 4)
212− , benchIOSink value "mapM" (mapM fromSerial 4)
220+ [ benchIOSink value "map" (mapN 4)
221+ , benchIOSink value "mapM" (mapM 4)
213222 , benchIOSink value "trace" (trace 4)
214223
224+#ifdef USE_PRELUDE
215225 , benchIOSink value "scanl'" (scanl' 4)
216226 , benchIOSink value "scanl1'" (scanl1' 4)
217227 , benchIOSink value "scanlM'" (scanlM' 4)
218228 , benchIOSink value "scanl1M'" (scanl1M' 4)
219229 , benchIOSink value "postscanl'" (postscanl' 4)
220230 , benchIOSink value "postscanlM'" (postscanlM' 4)
221−
231+#endif
222232 ]
223233 ]
224234
225235{-# INLINE sieveScan #-}
226236sieveScan :: Monad m => SerialT m Int -> SerialT m Int
227237sieveScan =
228− S.mapMaybe snd
229− . S.scanlM' (\(primes, _) n -> do
238+ Stream.mapMaybe snd
239+ . Stream.scan (FL.foldlM' (\(primes, _) n -> do
230240 return $
231241 let ps = takeWhile (\p -> p * p <= n) primes
232242 in if all (\p -> n `mod` p /= 0) ps
233243 then (primes ++ [n], Just n)
234− else (primes, Nothing)) (return ([2], Just 2))
244+ else (primes, Nothing)) (return ([2], Just 2)))
235245
236246o_n_space_mapping :: Int -> [Benchmark]
237247o_n_space_mapping value =
238248 [ bgroup "mapping"
239249 [ benchIO "naive prime sieve"
240− (\n -> S.sum $ sieveScan $ S.enumerateFromTo 2 (value + n))
250+ (\n -> Stream.fold FL.sum $ sieveScan $ Common.enumerateFromTo 2 (value + n))
241251 ]
242252 ]
243253
@@ -248,8 +258,8 @@ o_n_space_mapping value =
248258o_1_space_functor :: Int -> [Benchmark]
249259o_1_space_functor value =
250260 [ bgroup "Functor"
251− [ benchIOSink value "fmap" (fmapN fromSerial 1)
252− , benchIOSink value "fmap x 4" (fmapN fromSerial 4)
261+ [ benchIOSink value "fmap" (mapN 1)
262+ , benchIOSink value "fmap x 4" (mapN 4)
253263 ]
254264 ]
255265
@@ -259,124 +269,124 @@ o_1_space_functor value =
259269
260270{-# INLINE filterEven #-}
261271filterEven :: MonadIO m => Int -> SerialT m Int -> m ()
262−filterEven n = composeN n $ S.filter even
272+filterEven n = composeN n $ Stream.filter even
263273
264274{-# INLINE filterAllOut #-}
265275filterAllOut :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
266−filterAllOut value n = composeN n $ S.filter (> (value + 1))
276+filterAllOut value n = composeN n $ Stream.filter (> (value + 1))
267277
268278{-# INLINE filterAllIn #-}
269279filterAllIn :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
270−filterAllIn value n = composeN n $ S.filter (<= (value + 1))
280+filterAllIn value n = composeN n $ Stream.filter (<= (value + 1))
271281
272282{-# INLINE filterMEven #-}
273283filterMEven :: MonadIO m => Int -> SerialT m Int -> m ()
274−filterMEven n = composeN n $ S.filterM (return . even)
284+filterMEven n = composeN n $ Stream.filterM (return . even)
275285
276286{-# INLINE filterMAllOut #-}
277287filterMAllOut :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
278−filterMAllOut value n = composeN n $ S.filterM (\x -> return $ x > (value + 1))
288+filterMAllOut value n = composeN n $ Stream.filterM (\x -> return $ x > (value + 1))
279289
280290{-# INLINE filterMAllIn #-}
281291filterMAllIn :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
282−filterMAllIn value n = composeN 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)
292+filterMAllIn value n = composeN n $ Stream.filterM (\x -> return $ x <= (value + 1))
287293
288294{-# INLINE _takeOne #-}
289295_takeOne :: MonadIO m => Int -> SerialT m Int -> m ()
290−_takeOne n = composeN n $ S.take 1
296+_takeOne n = composeN n $ Stream.take 1
291297
292298{-# INLINE takeAll #-}
293299takeAll :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
294−takeAll value n = composeN n $ S.take (value + 1)
300+takeAll value n = composeN n $ Stream.take (value + 1)
295301
296302{-# INLINE takeWhileTrue #-}
297303takeWhileTrue :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
298−takeWhileTrue value n = composeN n $ S.takeWhile (<= (value + 1))
304+takeWhileTrue value n = composeN n $ Stream.takeWhile (<= (value + 1))
299305
300306{-# INLINE takeWhileMTrue #-}
301307takeWhileMTrue :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
302−takeWhileMTrue value n = composeN n $ S.takeWhileM (return . (<= (value + 1)))
308+takeWhileMTrue value n = composeN n $ Stream.takeWhileM (return . (<= (value + 1)))
303309
310+#ifdef USE_PRELUDE
304311{-# INLINE takeInterval #-}
305312takeInterval :: NanoSecond64 -> Int -> SerialT IO Int -> IO ()
306−takeInterval i n = composeN n (Internal.takeInterval i)
313+takeInterval i n = composeN n (Stream.takeInterval i)
307314
308315#ifdef INSPECTION
309316-- inspect $ hasNoType 'takeInterval ''SPEC
310317inspect $ hasNoTypeClasses 'takeInterval
311318-- inspect $ 'takeInterval `hasNoType` ''D.Step
312319#endif
320+#endif
313321
314322{-# INLINE dropOne #-}
315323dropOne :: MonadIO m => Int -> SerialT m Int -> m ()
316−dropOne n = composeN n $ S.drop 1
324+dropOne n = composeN n $ Stream.drop 1
317325
318326{-# INLINE dropAll #-}
319327dropAll :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
320−dropAll value n = composeN n $ S.drop (value + 1)
328+dropAll value n = composeN n $ Stream.drop (value + 1)
321329
322330{-# INLINE dropWhileTrue #-}
323331dropWhileTrue :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
324−dropWhileTrue value n = composeN n $ S.dropWhile (<= (value + 1))
332+dropWhileTrue value n = composeN n $ Stream.dropWhile (<= (value + 1))
325333
326334{-# INLINE dropWhileMTrue #-}
327335dropWhileMTrue :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
328−dropWhileMTrue value n = composeN n $ S.dropWhileM (return . (<= (value + 1)))
336+dropWhileMTrue value n = composeN n $ Stream.dropWhileM (return . (<= (value + 1)))
329337
330338{-# INLINE dropWhileFalse #-}
331339dropWhileFalse :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
332−dropWhileFalse value n = composeN n $ S.dropWhile (> (value + 1))
340+dropWhileFalse value n = composeN n $ Stream.dropWhile (> (value + 1))
333341
342+#ifdef USE_PRELUDE
334343-- XXX Decide on the time interval
335344{-# INLINE _intervalsOfSum #-}
336345_intervalsOfSum :: MonadAsync m => Double -> Int -> SerialT m Int -> m ()
337−_intervalsOfSum i n = composeN n (S.intervalsOf i FL.sum)
346+_intervalsOfSum i n = composeN n (Stream.intervalsOf i FL.sum)
338347
339348{-# INLINE dropInterval #-}
340349dropInterval :: NanoSecond64 -> Int -> SerialT IO Int -> IO ()
341−dropInterval i n = composeN n (Internal.dropInterval i)
350+dropInterval i n = composeN n (Stream.dropInterval i)
342351
343352#ifdef INSPECTION
344353inspect $ hasNoTypeClasses 'dropInterval
345354-- inspect $ 'dropInterval `hasNoType` ''D.Step
346355#endif
356+#endif
347357
348358{-# INLINE findIndices #-}
349359findIndices :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
350−findIndices value n = composeN n $ S.findIndices (== (value + 1))
360+findIndices value n = composeN n $ Stream.findIndices (== (value + 1))
351361
352362{-# INLINE elemIndices #-}
353363elemIndices :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
354−elemIndices value n = composeN n $ S.elemIndices (value + 1)
364+elemIndices value n = composeN n $ Stream.elemIndices (value + 1)
355365
356366{-# INLINE deleteBy #-}
357367deleteBy :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
358−deleteBy value n = composeN n $ S.deleteBy (>=) (value + 1)
368+deleteBy value n = composeN n $ Stream.deleteBy (>=) (value + 1)
359369
360370-- uniq . uniq == uniq, composeN 2 ~ composeN 1
361371{-# INLINE uniq #-}
362372uniq :: MonadIO m => Int -> SerialT m Int -> m ()
363−uniq n = composeN n S.uniq
373+uniq n = composeN n Stream.uniq
364374
365375{-# INLINE mapMaybe #-}
366376mapMaybe :: MonadIO m => Int -> SerialT m Int -> m ()
367377mapMaybe n =
368378 composeN n $
369− S.mapMaybe
379+ Stream.mapMaybe
370380 (\x ->
371381 if odd x
372382 then Nothing
373383 else Just x)
374384
375385{-# INLINE mapMaybeM #-}
376−mapMaybeM :: S.MonadAsync m => Int -> SerialT m Int -> m ()
386+mapMaybeM :: MonadAsync m => Int -> SerialT m Int -> m ()
377387mapMaybeM n =
378388 composeN n $
379− S.mapMaybeM
389+ Stream.mapMaybeM
380390 (\x ->
381391 if odd x
382392 then return Nothing
@@ -393,22 +403,22 @@ o_1_space_filtering value =
393403 , benchIOSink value "filterM-all-out" (filterMAllOut value 1)
394404 , benchIOSink value "filterM-all-in" (filterMAllIn value 1)
395405
396− , benchIOSink value "foldFilter-even" (foldFilterEven 1)
397−
398406 -- Trimming
399407 , benchIOSink value "take-all" (takeAll value 1)
400− , benchIOSink
401− value
402− "takeInterval-all"
403− (takeInterval (NanoSecond64 maxBound) 1)
404408 , benchIOSink value "takeWhile-true" (takeWhileTrue value 1)
405409 -- , benchIOSink value "takeWhileM-true" (_takeWhileMTrue value 1)
406410 , benchIOSink value "drop-one" (dropOne 1)
407411 , benchIOSink value "drop-all" (dropAll value 1)
412+#ifdef USE_PRELUDE
413+ , benchIOSink
414+ value
415+ "takeInterval-all"
416+ (takeInterval (NanoSecond64 maxBound) 1)
408417 , benchIOSink
409418 value
410419 "dropInterval-all"
411420 (dropInterval (NanoSecond64 maxBound) 1)
421+#endif
412422 , benchIOSink value "dropWhile-true" (dropWhileTrue value 1)
413423 -- , benchIOSink value "dropWhileM-true" (_dropWhileMTrue value 1)
414424 , benchIOSink
@@ -440,8 +450,6 @@ o_1_space_filteringX4 value =
440450 , benchIOSink value "filterM-all-out" (filterMAllOut value 4)
441451 , benchIOSink value "filterM-all-in" (filterMAllIn value 4)
442452
443− , benchIOSink value "foldFilter-even" (foldFilterEven 4)
444−
445453 -- trimming
446454 , benchIOSink value "take-all" (takeAll value 4)
447455 , benchIOSink value "takeWhile-true" (takeWhileTrue value 4)
@@ -473,26 +481,26 @@ o_1_space_filteringX4 value =
473481-------------------------------------------------------------------------------
474482
475483{-# INLINE intersperse #-}
476−intersperse :: S.MonadAsync m => Int -> Int -> SerialT m Int -> m ()
477−intersperse value n = composeN n $ S.intersperse (value + 1)
484+intersperse :: MonadAsync m => Int -> Int -> SerialT m Int -> m ()
485+intersperse value n = composeN n $ Stream.intersperse (value + 1)
478486
479487{-# INLINE intersperseM #-}
480−intersperseM :: S.MonadAsync m => Int -> Int -> SerialT m Int -> m ()
481−intersperseM value n = composeN n $ S.intersperseM (return $ value + 1)
488+intersperseM :: MonadAsync m => Int -> Int -> SerialT m Int -> m ()
489+intersperseM value n = composeN n $ Stream.intersperseM (return $ value + 1)
482490
483491{-# INLINE insertBy #-}
484492insertBy :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
485−insertBy value n = composeN n $ S.insertBy compare (value + 1)
493+insertBy value n = composeN n $ Stream.insertBy compare (value + 1)
486494
487495{-# INLINE interposeSuffix #-}
488−interposeSuffix :: S.MonadAsync m => Int -> Int -> SerialT m Int -> m ()
496+interposeSuffix :: Monad m => Int -> Int -> SerialT m Int -> m ()
489497interposeSuffix value n =
490− composeN n $ Internal.interposeSuffix (value + 1) Unfold.identity
498+ composeN n $ Stream.interposeSuffix (value + 1) Unfold.identity
491499
492500{-# INLINE intercalateSuffix #-}
493−intercalateSuffix :: S.MonadAsync m => Int -> Int -> SerialT m Int -> m ()
501+intercalateSuffix :: Monad m => Int -> Int -> SerialT m Int -> m ()
494502intercalateSuffix value n =
495− composeN n $ Internal.intercalateSuffix Unfold.identity (value + 1)
503+ composeN n $ Stream.intercalateSuffix Unfold.identity (value + 1)
496504
497505o_1_space_inserting :: Int -> [Benchmark]
498506o_1_space_inserting value =
@@ -519,11 +527,11 @@ o_1_space_insertingX4 value =
519527
520528{-# INLINE indexed #-}
521529indexed :: MonadIO m => Int -> SerialT m Int -> m ()
522−indexed n = composeN n (S.map snd . S.indexed)
530+indexed n = composeN n (fmap snd . Stream.indexed)
523531
524532{-# INLINE indexedR #-}
525533indexedR :: MonadIO m => Int -> Int -> SerialT m Int -> m ()
526−indexedR value n = composeN n (S.map snd . S.indexedR value)
534+indexedR value n = composeN n (fmap snd . Stream.indexedR value)
527535
528536o_1_space_indexing :: Int -> [Benchmark]
529537o_1_space_indexing value =
benchmark/bench-runner/Main.hs+9−9
@@ -35,22 +35,22 @@ rtsOpts exeName benchName0 = unwords [general, exeSpecific, benchSpecific]
3535 `isPrefixOf` benchName = "-K2M -M256M"
3636 | "Prelude.Rate/o-1-space." `isPrefixOf` benchName = "-K128K"
3737 | "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 =
3939 "-K64M"
40− | "Prelude.Serial/o-n-heap.grouping.classifySessionsOf"
40+ | "Data.Stream/o-n-heap.grouping.classifySessionsOf"
4141 `isPrefixOf` benchName = "-K1M -M32M"
42− | "Prelude.Serial/o-n-heap.Functor." `isPrefixOf` benchName =
42+ | "Data.Stream/o-n-heap.Functor." `isPrefixOf` benchName =
4343 "-K4M -M32M"
44− | "Prelude.Serial/o-n-heap.transformer." `isPrefixOf` benchName =
44+ | "Data.Stream/o-n-heap.transformer." `isPrefixOf` benchName =
4545 "-K8M -M64M"
46− | "Prelude.Serial/o-n-space.Functor." `isPrefixOf` benchName =
46+ | "Data.Stream/o-n-space.Functor." `isPrefixOf` benchName =
4747 "-K4M -M64M"
48− | "Prelude.Serial/o-n-space.Applicative." `isPrefixOf` benchName =
48+ | "Data.Stream/o-n-space.Applicative." `isPrefixOf` benchName =
4949 "-K8M -M128M"
50− | "Prelude.Serial/o-n-space.Monad." `isPrefixOf` benchName =
50+ | "Data.Stream/o-n-space.Monad." `isPrefixOf` benchName =
5151 "-K8M -M64M"
52− | "Prelude.Serial/o-n-space.grouping." `isPrefixOf` benchName = ""
53− | "Prelude.Serial/o-n-space." `isPrefixOf` benchName = "-K4M"
52+ | "Data.Stream/o-n-space.grouping." `isPrefixOf` benchName = ""
53+ | "Data.Stream/o-n-space." `isPrefixOf` benchName = "-K4M"
5454 | "Prelude.WSerial/o-n-space." `isPrefixOf` benchName = "-K4M"
5555 | "Prelude.Async/o-n-space.monad-outer-product." `isPrefixOf` benchName =
5656 "-K4M"
benchmark/streamly-benchmarks.cabal+22−12
@@ -64,6 +64,11 @@ flag bench-core
6464 manual: True
6565 default: False
6666
67+flag use-prelude
68+ description: Use Prelude instead of Data.Stream for serial benchmarks
69+ manual: True
70+ default: False
71+
6772-------------------------------------------------------------------------------
6873-- Common stanzas
6974-------------------------------------------------------------------------------
@@ -71,6 +76,9 @@ flag bench-core
7176common compile-options
7277 default-language: Haskell2010
7378
79+ if flag(use-prelude)
80+ cpp-options: -DUSE_PRELUDE
81+
7482 if flag(dev)
7583 cpp-options: -DDEVBUILD
7684
@@ -201,20 +209,23 @@ common bench-options-threaded
201209-- Serial Streams
202210-------------------------------------------------------------------------------
203211
204−benchmark Prelude.Serial
212+benchmark Data.Stream
205213 import: bench-options
206214 type: exitcode-stdio-1.0
207− hs-source-dirs: Streamly/Benchmark/Prelude
208− main-is: Serial.hs
215+ hs-source-dirs: Streamly/Benchmark/Data
216+ main-is: Stream.hs
209217 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+ Stream.Generate
219+ Stream.Eliminate
220+ Stream.Transform
221+ Stream.Reduce
222+ Stream.Expand
223+ Stream.Exceptions
224+ Stream.Lift
225+ Stream.Common
226+ if flag(use-prelude)
227+ other-modules:
228+ Stream.Split
218229 if flag(bench-core) || impl(ghcjs)
219230 buildable: False
220231 else
@@ -225,7 +236,6 @@ benchmark Prelude.Serial
225236 else
226237 ghc-options: +RTS -M2500M -RTS
227238
228−
229239benchmark Prelude.WSerial
230240 import: bench-options
231241 type: exitcode-stdio-1.0
hie.yaml+10−18
@@ -30,6 +30,16 @@ cradle:
3030 component: "bench:Data.Stream.StreamD"
3131 - path: "./benchmark/Streamly/Benchmark/Data/Stream/StreamK.hs"
3232 component: "bench:Data.Stream.StreamK"
33+ - path: "./benchmark/Streamly/Benchmark/Data/Stream/Common.hs"
34+ component: "bench:Data.Stream"
35+ - path: "./benchmark/Streamly/Benchmark/Data/Stream/Expand.hs"
36+ component: "bench:Data.Stream"
37+ - path: "./benchmark/Streamly/Benchmark/Data/Stream/Generate.hs"
38+ component: "bench:Data.Stream"
39+ - path: "./benchmark/Streamly/Benchmark/Data/Stream/Reduce.hs"
40+ component: "bench:Data.Stream"
41+ - path: "./benchmark/Streamly/Benchmark/Data/Stream/Transform.hs"
42+ component: "bench:Data.Stream"
3343 - path: "./benchmark/Streamly/Benchmark/Data/Unfold.hs"
3444 component: "bench:Data.Unfold"
3545 - path: "./benchmark/Streamly/Benchmark/FileSystem/Handle/Read.hs"
@@ -44,24 +54,6 @@ cradle:
4454 component: "bench:Prelude.Merge"
4555 - path: "./benchmark/Streamly/Benchmark/Prelude/Parallel.hs"
4656 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"
6557 - path: "./benchmark/Streamly/Benchmark/Prelude/WSerial.hs"
6658 component: "bench:Prelude.WSerial"
6759 - path: "./benchmark/Streamly/Benchmark/Prelude/ZipSerial.hs"
streamly.cabal−1
@@ -65,7 +65,6 @@ extra-source-files:
6565 benchmark/Streamly/Benchmark/FileSystem/*.hs
6666 benchmark/Streamly/Benchmark/FileSystem/Handle/*.hs
6767 benchmark/Streamly/Benchmark/Prelude/*.hs
68− benchmark/Streamly/Benchmark/Prelude/Serial/*.hs
6968 benchmark/Streamly/Benchmark/Unicode/*.hs
7069 benchmark/lib/Streamly/Benchmark/*.hs
7170 benchmark/lib/Streamly/Benchmark/Common/*.hs
targets/Targets.hs+2−2
@@ -25,9 +25,9 @@ targets =
2525 )
2626
2727 -- Streams
28− , ("Prelude.Serial", ["serial_wserial_cmp"])
28+ , ("Data.Stream", ["serial_wserial_cmp"])
2929 , ("Prelude.WSerial", ["serial_wserial_cmp"])
30− , ("Prelude.Serial",
30+ , ("Data.Stream",
3131 [ "prelude_serial_grp"
3232 , "infinite_grp"
3333 , "serial_wserial_cmp"