on master help sign in
Renamed function/bench names appropriatly in bench:StreamK
f1f8d7aAdithya Kumar
benchmark/Streamly/Benchmark/Data/Stream/StreamK.hs+248−178
@@ -24,7 +24,7 @@ import Control.Monad (when)
24import Data.Maybe (isJust)
24import Data.Maybe (isJust)
25import System.Random (randomRIO)
25import System.Random (randomRIO)
26import Prelude hiding
26import Prelude hiding
27− (tail, mapM_, foldl, last, map, mapM, concatMap, zip, init)
27+ (tail, mapM_, foldl, last, map, mapM, concatMap, zipWith, init)
28
28
29import qualified Prelude as P
29import qualified Prelude as P
30import qualified Data.List as List
30import qualified Data.List as List
@@ -40,37 +40,111 @@ import Streamly.Benchmark.Common
40import Test.Inspection
40import Test.Inspection
41#endif
41#endif
42
42
43+{-
44+
45+Benchmarks that need to be added
46+
47+-- repeat
48+-- repeatM
49+-- replicate
50+-- replicateM
51+-- iterate
52+-- iterateM
53+-- fromList
54+
55+-- bindWith
56+-- concatPairsWith
57+-- apWith
58+-- apSerial
59+-- apSerialDiscardFst
60+-- apSerialDiscardSnd
61+
62+-- the
63+-- serial
64+-- consMStream
65+-- withLocal
66+-- mfix
67+
68+-- elem
69+-- notElem
70+-- all
71+-- any
72+-- minimum
73+-- minimumBy
74+-- maximum
75+-- maximumBy
76+-- findIndices
77+-- lookup
78+-- findM
79+-- find
80+-- (!!)
81+
82+-- foldlM'
83+-- foldlT
84+-- foldlx'
85+-- foldlMx'
86+-- fold
87+
88+-- sequence
89+
90+-- foldrSM
91+-- buildS
92+-- buildM
93+-- augmentS
94+-- augmentSM
95+-- foldr
96+-- foldr1
97+-- foldrM
98+-- foldrT
99+
100+-- intersperseM
101+-- insertBy
102+-- deleteBy
103+-- reverse
104+-- mapMaybe
105+
106+-- zipWithM
107+-- mergeBy
108+-- mergeByM
109+
110+-- toStreamK (Probably can be skipped)
111+-- hoist
112+
113+-- scanlx'
114+
115+-}
116+
43-------------------------------------------------------------------------------
117-------------------------------------------------------------------------------
44-- Stream generation and elimination
118-- Stream generation and elimination
45-------------------------------------------------------------------------------
119-------------------------------------------------------------------------------
46
120
47type Stream m a = S.Stream m a
121type Stream m a = S.Stream m a
48
122
49−{-# INLINE sourceUnfoldr #-}
123+{-# INLINE unfoldr #-}
50−sourceUnfoldr :: Int -> Int -> Stream m Int
124+unfoldr :: Int -> Int -> Stream m Int
51−sourceUnfoldr streamLen n = S.unfoldr step n
125+unfoldr streamLen n = S.unfoldr step n
52 where
126 where
53 step cnt =
127 step cnt =
54 if cnt > n + streamLen
128 if cnt > n + streamLen
55 then Nothing
129 then Nothing
56 else Just (cnt, cnt + 1)
130 else Just (cnt, cnt + 1)
57
131
58−{-# INLINE sourceUnfoldrM #-}
132+{-# INLINE unfoldrM #-}
59−sourceUnfoldrM :: S.MonadAsync m => Int -> Int -> Stream m Int
133+unfoldrM :: S.MonadAsync m => Int -> Int -> Stream m Int
60−sourceUnfoldrM streamLen n = S.unfoldrM step n
134+unfoldrM streamLen n = S.unfoldrM step n
61 where
135 where
62 step cnt =
136 step cnt =
63 if cnt > n + streamLen
137 if cnt > n + streamLen
64 then return Nothing
138 then return Nothing
65 else return (Just (cnt, cnt + 1))
139 else return (Just (cnt, cnt + 1))
66
140
67−{-# INLINE sourceFromFoldable #-}
141+{-# INLINE fromFoldable #-}
68−sourceFromFoldable :: Int -> Int -> Stream m Int
142+fromFoldable :: Int -> Int -> Stream m Int
69−sourceFromFoldable streamLen n = S.fromFoldable [n..n+streamLen]
143+fromFoldable streamLen n = S.fromFoldable [n..n+streamLen]
70
144
71−{-# INLINE sourceFromFoldableM #-}
145+{-# INLINE fromFoldableM #-}
72−sourceFromFoldableM :: S.MonadAsync m => Int -> Int -> Stream m Int
146+fromFoldableM :: S.MonadAsync m => Int -> Int -> Stream m Int
73−sourceFromFoldableM streamLen n =
147+fromFoldableM streamLen n =
74 Prelude.foldr S.consM S.nil (Prelude.fmap return [n..n+streamLen])
148 Prelude.foldr S.consM S.nil (Prelude.fmap return [n..n+streamLen])
75
149
76{-# INLINABLE concatMapFoldableWith #-}
150{-# INLINABLE concatMapFoldableWith #-}
@@ -78,32 +152,27 @@ concatMapFoldableWith :: (S.IsStream t, Foldable f)
78 => (t m b -> t m b -> t m b) -> (a -> t m b) -> f a -> t m b
152 => (t m b -> t m b -> t m b) -> (a -> t m b) -> f a -> t m b
79concatMapFoldableWith f g = Prelude.foldr (f . g) S.nil
153concatMapFoldableWith f g = Prelude.foldr (f . g) S.nil
80
154
81−{-# INLINE sourceFoldMapWith #-}
155+{-# INLINE concatMapFoldableSerial #-}
82−sourceFoldMapWith :: Int -> Int -> Stream m Int
156+concatMapFoldableSerial :: Int -> Int -> Stream m Int
83−sourceFoldMapWith streamLen n = concatMapFoldableWith S.serial S.yield [n..n+streamLen]
157+concatMapFoldableSerial streamLen n = concatMapFoldableWith S.serial S.yield [n..n+streamLen]
84
158
85−{-# INLINE sourceFoldMapWithM #-}
159+{-# INLINE concatMapFoldableSerialM #-}
86−sourceFoldMapWithM :: Monad m => Int -> Int -> Stream m Int
160+concatMapFoldableSerialM :: Monad m => Int -> Int -> Stream m Int
87−sourceFoldMapWithM streamLen n =
161+concatMapFoldableSerialM streamLen n =
88 concatMapFoldableWith S.serial (S.yieldM . return) [n..n+streamLen]
162 concatMapFoldableWith S.serial (S.yieldM . return) [n..n+streamLen]
89
163
90-------------------------------------------------------------------------------
164-------------------------------------------------------------------------------
91-- Elimination
165-- Elimination
92-------------------------------------------------------------------------------
166-------------------------------------------------------------------------------
93
167
94−{-# INLINE runStream #-}
168+{-# INLINE drain #-}
95−runStream :: Monad m => Stream m a -> m ()
169+drain :: Monad m => Stream m a -> m ()
96−runStream = S.drain
170+drain = S.drain
97−-- runStream = S.mapM_ (\_ -> return ())
98
171
99{-# INLINE mapM_ #-}
172{-# INLINE mapM_ #-}
100mapM_ :: Monad m => Stream m a -> m ()
173mapM_ :: Monad m => Stream m a -> m ()
101mapM_ = S.mapM_ (\_ -> return ())
174mapM_ = S.mapM_ (\_ -> return ())
102
175
103−{-# INLINE toNull #-}
104−toNull :: Monad m => Stream m Int -> m ()
105−toNull = runStream
106−
107{-# INLINE uncons #-}
176{-# INLINE uncons #-}
108uncons :: Monad m => Stream m Int -> m ()
177uncons :: Monad m => Stream m Int -> m ()
109uncons s = do
178uncons s = do
@@ -138,9 +207,9 @@ headTail s = do
138toList :: Monad m => Stream m Int -> m [Int]
207toList :: Monad m => Stream m Int -> m [Int]
139toList = S.toList
208toList = S.toList
140
209
141−{-# INLINE foldl #-}
210+{-# INLINE foldl' #-}
142−foldl :: Monad m => Stream m Int -> m Int
211+foldl' :: Monad m => Stream m Int -> m Int
143−foldl = S.foldl' (+) 0
212+foldl' = S.foldl' (+) 0
144
213
145{-# INLINE last #-}
214{-# INLINE last #-}
146last :: Monad m => Stream m Int -> m (Maybe Int)
215last :: Monad m => Stream m Int -> m (Maybe Int)
@@ -150,29 +219,25 @@ last = S.last
150-- Transformation
219-- Transformation
151-------------------------------------------------------------------------------
220-------------------------------------------------------------------------------
152
221
153−{-# INLINE transform #-}
154−transform :: Monad m => Stream m a -> m ()
155−transform = runStream
156−
157{-# INLINE composeN #-}
222{-# INLINE composeN #-}
158composeN
223composeN
159 :: Monad m
224 :: Monad m
160 => Int -> (Stream m Int -> Stream m Int) -> Stream m Int -> m ()
225 => Int -> (Stream m Int -> Stream m Int) -> Stream m Int -> m ()
161composeN n f =
226composeN n f =
162 case n of
227 case n of
163− 1 -> transform . f
228+ 1 -> drain . f
164− 2 -> transform . f . f
229+ 2 -> drain . f . f
165− 3 -> transform . f . f . f
230+ 3 -> drain . f . f . f
166− 4 -> transform . f . f . f . f
231+ 4 -> drain . f . f . f . f
167 _ -> undefined
232 _ -> undefined
168
233
169−{-# INLINE scan #-}
234+{-# INLINE scanl' #-}
170−scan :: Monad m => Int -> Stream m Int -> m ()
235+scanl' :: Monad m => Int -> Stream m Int -> m ()
171−scan n = composeN n $ S.scanl' (+) 0
236+scanl' n = composeN n $ S.scanl' (+) 0
172
237
173{-# INLINE map #-}
238{-# INLINE map #-}
174map :: Monad m => Int -> Stream m Int -> m ()
239map :: Monad m => Int -> Stream m Int -> m ()
175−map n = composeN n $ P.fmap (+ 1)
240+map n = composeN n $ S.map (+ 1)
176
241
177{-# INLINE fmapK #-}
242{-# INLINE fmapK #-}
178fmapK :: Monad m => Int -> Stream m Int -> m ()
243fmapK :: Monad m => Int -> Stream m Int -> m ()
@@ -246,7 +311,7 @@ intersperse streamLen n = composeN n $ S.intersperse streamLen
246iterateSource
311iterateSource
247 :: S.MonadAsync m
312 :: S.MonadAsync m
248 => Int -> (Stream m Int -> Stream m Int) -> Int -> Int -> Stream m Int
313 => Int -> (Stream m Int -> Stream m Int) -> Int -> Int -> Stream m Int
249−iterateSource iterStreamLen g i n = f i (sourceUnfoldrM iterStreamLen n)
314+iterateSource iterStreamLen g i n = f i (unfoldrM iterStreamLen n)
250 where
315 where
251 f (0 :: Int) m = g m
316 f (0 :: Int) m = g m
252 f x m = g (f (x P.- 1) m)
317 f x m = g (f (x P.- 1) m)
@@ -286,9 +351,9 @@ iterateDropWhileTrue streamLen iterStreamLen maxIters = iterateSource iterStream
286-- Zipping
351-- Zipping
287-------------------------------------------------------------------------------
352-------------------------------------------------------------------------------
288
353
289−{-# INLINE zip #-}
354+{-# INLINE zipWith #-}
290−zip :: Monad m => Stream m Int -> m ()
355+zipWith :: Monad m => Stream m Int -> m ()
291−zip src = transform $ S.zipWith (,) src src
356+zipWith src = drain $ S.zipWith (,) src src
292
357
293-------------------------------------------------------------------------------
358-------------------------------------------------------------------------------
294-- Mixed Composition
359-- Mixed Composition
@@ -344,8 +409,8 @@ filterMap streamLen n = composeN n $ S.map (subtract 1) . S.filter (<= streamLen
344concatMap :: Int -> Int -> Int -> IO ()
409concatMap :: Int -> Int -> Int -> IO ()
345concatMap outer inner n =
410concatMap outer inner n =
346 S.drain $ S.concatMap
411 S.drain $ S.concatMap
347− (\_ -> sourceUnfoldrM inner n)
412+ (\_ -> unfoldrM inner n)
348− (sourceUnfoldrM outer n)
413+ (unfoldrM outer n)
349
414
350#ifdef INSPECTION
415#ifdef INSPECTION
351inspect $ hasNoTypeClasses 'concatMap
416inspect $ hasNoTypeClasses 'concatMap
@@ -357,8 +422,8 @@ inspect $ hasNoTypeClasses 'concatMap
357concatMapPure :: Int -> Int -> Int -> IO ()
422concatMapPure :: Int -> Int -> Int -> IO ()
358concatMapPure outer inner n =
423concatMapPure outer inner n =
359 S.drain $ S.concatMap
424 S.drain $ S.concatMap
360− (\_ -> sourceUnfoldr inner n)
425+ (\_ -> unfoldr inner n)
361− (sourceUnfoldr outer n)
426+ (unfoldr outer n)
362
427
363#ifdef INSPECTION
428#ifdef INSPECTION
364inspect $ hasNoTypeClasses 'concatMapPure
429inspect $ hasNoTypeClasses 'concatMapPure
@@ -369,7 +434,7 @@ inspect $ hasNoTypeClasses 'concatMapPure
369{-# INLINE concatMapRepl #-}
434{-# INLINE concatMapRepl #-}
370concatMapRepl :: Int -> Int -> Int -> IO ()
435concatMapRepl :: Int -> Int -> Int -> IO ()
371concatMapRepl outer inner n =
436concatMapRepl outer inner n =
372− S.drain $ S.concatMap (S.replicate inner) (sourceUnfoldrM outer n)
437+ S.drain $ S.concatMap (S.replicate inner) (unfoldrM outer n)
373
438
374#ifdef INSPECTION
439#ifdef INSPECTION
375inspect $ hasNoTypeClasses 'concatMapRepl
440inspect $ hasNoTypeClasses 'concatMapRepl
@@ -383,42 +448,42 @@ sourceConcatMapId :: Monad m
383sourceConcatMapId val n =
448sourceConcatMapId val n =
384 S.fromFoldable $ fmap (S.yieldM . return) [n..n+val]
449 S.fromFoldable $ fmap (S.yieldM . return) [n..n+val]
385
450
386−{-# INLINE concatStreamsWith #-}
451+{-# INLINE concatMapBySerial #-}
387−concatStreamsWith :: Int -> Int -> Int -> IO ()
452+concatMapBySerial :: Int -> Int -> Int -> IO ()
388−concatStreamsWith outer inner n =
453+concatMapBySerial outer inner n =
389 S.drain $ S.concatMapBy S.serial
454 S.drain $ S.concatMapBy S.serial
390− (sourceUnfoldrM inner)
455+ (unfoldrM inner)
391− (sourceUnfoldrM outer n)
456+ (unfoldrM outer n)
392
457
393-------------------------------------------------------------------------------
458-------------------------------------------------------------------------------
394-- Nested Composition
459-- Nested Composition
395-------------------------------------------------------------------------------
460-------------------------------------------------------------------------------
396
461
397−{-# INLINE toNullApNested #-}
462+{-# INLINE drainApplicative #-}
398−toNullApNested :: Monad m => Stream m Int -> m ()
463+drainApplicative :: Monad m => Stream m Int -> m ()
399−toNullApNested s = runStream $ do
464+drainApplicative s = drain $ do
400 (+) <$> s <*> s
465 (+) <$> s <*> s
401
466
402−{-# INLINE toNullNested #-}
467+{-# INLINE drainMonad #-}
403−toNullNested :: Monad m => Stream m Int -> m ()
468+drainMonad :: Monad m => Stream m Int -> m ()
404−toNullNested s = runStream $ do
469+drainMonad s = drain $ do
405 x <- s
470 x <- s
406 y <- s
471 y <- s
407 return $ x + y
472 return $ x + y
408
473
409−{-# INLINE toNullNested3 #-}
474+{-# INLINE drainMonad3 #-}
410−toNullNested3 :: Monad m => Stream m Int -> m ()
475+drainMonad3 :: Monad m => Stream m Int -> m ()
411−toNullNested3 s = runStream $ do
476+drainMonad3 s = drain $ do
412 x <- s
477 x <- s
413 y <- s
478 y <- s
414 z <- s
479 z <- s
415 return $ x + y + z
480 return $ x + y + z
416
481
417−{-# INLINE filterAllOutNested #-}
482+{-# INLINE filterAllOutMonad #-}
418−filterAllOutNested
483+filterAllOutMonad
419 :: Monad m
484 :: Monad m
420 => Stream m Int -> m ()
485 => Stream m Int -> m ()
421−filterAllOutNested str = runStream $ do
486+filterAllOutMonad str = drain $ do
422 x <- str
487 x <- str
423 y <- str
488 y <- str
424 let s = x + y
489 let s = x + y
@@ -426,11 +491,11 @@ filterAllOutNested str = runStream $ do
426 then return s
491 then return s
427 else S.nil
492 else S.nil
428
493
429−{-# INLINE filterAllInNested #-}
494+{-# INLINE filterAllInMonad #-}
430−filterAllInNested
495+filterAllInMonad
431 :: Monad m
496 :: Monad m
432 => Stream m Int -> m ()
497 => Stream m Int -> m ()
433−filterAllInNested str = runStream $ do
498+filterAllInMonad str = drain $ do
434 x <- str
499 x <- str
435 y <- str
500 y <- str
436 let s = x + y
501 let s = x + y
@@ -442,9 +507,14 @@ filterAllInNested str = runStream $ do
442-- Nested Composition Pure lists
507-- Nested Composition Pure lists
443-------------------------------------------------------------------------------
508-------------------------------------------------------------------------------
444
509
445−{-# INLINE sourceUnfoldrList #-}
510+-- There are several list benchmarks here for comparison with lists. It is easy
446−sourceUnfoldrList :: Int -> Int -> [Int]
511+-- and convenient to see the comparisons when they are here, otherwise we'll
512+-- have to add a separate module for list benchmarks with the same names and
513+-- then add a comparison in bench.sh.
514+
515+{-# INLINE unfoldrList #-}
516+unfoldrList :: Int -> Int -> [Int]
447−sourceUnfoldrList maxval n = List.unfoldr step n
517+unfoldrList maxval n = List.unfoldr step n
448 where
518 where
449 step cnt =
519 step cnt =
450 if cnt > n + maxval
520 if cnt > n + maxval
@@ -500,41 +570,41 @@ moduleName = "Data.Stream.StreamK"
500o_1_space_generation :: Int -> Benchmark
570o_1_space_generation :: Int -> Benchmark
501o_1_space_generation streamLen =
571o_1_space_generation streamLen =
502 bgroup "generation"
572 bgroup "generation"
503− [ benchFold "unfoldr" toNull (sourceUnfoldr streamLen)
573+ [ benchFold "unfoldr" drain (unfoldr streamLen)
504− , benchFold "unfoldrM" toNull (sourceUnfoldrM streamLen)
574+ , benchFold "unfoldrM" drain (unfoldrM streamLen)
505
575
506− , benchFold "fromFoldable" toNull (sourceFromFoldable streamLen)
576+ , benchFold "fromFoldable" drain (fromFoldable streamLen)
507− , benchFold "fromFoldableM" toNull (sourceFromFoldableM streamLen)
577+ , benchFold "fromFoldableM" drain (fromFoldableM streamLen)
508
578
509 -- appends
579 -- appends
510− , benchFold "concatMapFoldableWith" toNull (sourceFoldMapWith streamLen)
580+ , benchFold "concatMapFoldableWith" drain (concatMapFoldableSerial streamLen)
511− , benchFold "concatMapFoldableWithM" toNull (sourceFoldMapWithM streamLen)
581+ , benchFold "concatMapFoldableWithM" drain (concatMapFoldableSerialM streamLen)
512 ]
582 ]
513
583
514o_1_space_elimination :: Int -> Benchmark
584o_1_space_elimination :: Int -> Benchmark
515o_1_space_elimination streamLen =
585o_1_space_elimination streamLen =
516 bgroup "elimination"
586 bgroup "elimination"
517− [ benchFold "toNull" toNull (sourceUnfoldrM streamLen)
587+ [ benchFold "toNull" drain (unfoldrM streamLen)
518− , benchFold "mapM_" mapM_ (sourceUnfoldrM streamLen)
588+ , benchFold "mapM_" mapM_ (unfoldrM streamLen)
519− , benchFold "uncons" uncons (sourceUnfoldrM streamLen)
589+ , benchFold "uncons" uncons (unfoldrM streamLen)
520− , benchFold "init" init (sourceUnfoldrM streamLen)
590+ , benchFold "init" init (unfoldrM streamLen)
521− , benchFold "foldl'" foldl (sourceUnfoldrM streamLen)
591+ , benchFold "foldl'" foldl' (unfoldrM streamLen)
522− , benchFold "last" last (sourceUnfoldrM streamLen)
592+ , benchFold "last" last (unfoldrM streamLen)
523 ]
593 ]
524
594
525o_1_space_nested :: Int -> Benchmark
595o_1_space_nested :: Int -> Benchmark
526o_1_space_nested streamLen =
596o_1_space_nested streamLen =
527 bgroup "nested"
597 bgroup "nested"
528− [ benchFold "toNullAp" toNullApNested (sourceUnfoldrM streamLen2)
598+ [ benchFold "drainApplicative" drainApplicative (unfoldrM streamLen2)
529− , benchFold "toNull" toNullNested (sourceUnfoldrM streamLen2)
599+ , benchFold "drainMonad" drainMonad (unfoldrM streamLen2)
530− , benchFold "toNull3" toNullNested3 (sourceUnfoldrM streamLen3)
600+ , benchFold "drainMonad3" drainMonad3 (unfoldrM streamLen3)
531− , benchFold "filterAllIn" filterAllInNested (sourceUnfoldrM streamLen2)
601+ , benchFold "filterAllInMonad" filterAllInMonad (unfoldrM streamLen2)
532− , benchFold "filterAllOut" filterAllOutNested (sourceUnfoldrM streamLen2)
602+ , benchFold "filterAllOutMonad" filterAllOutMonad (unfoldrM streamLen2)
533− , benchFold "toNullApPure" toNullApNested (sourceUnfoldr streamLen2)
603+ , benchFold "drainApplicative (pure)" drainApplicative (unfoldr streamLen2)
534− , benchFold "toNullPure" toNullNested (sourceUnfoldr streamLen2)
604+ , benchFold "drainMonad (pure)" drainMonad (unfoldr streamLen2)
535− , benchFold "toNull3Pure" toNullNested3 (sourceUnfoldr streamLen3)
605+ , benchFold "drainMonad3 (pure)" drainMonad3 (unfoldr streamLen3)
536− , benchFold "filterAllInPure" filterAllInNested (sourceUnfoldr streamLen2)
606+ , benchFold "filterAllInMonad (pure)" filterAllInMonad (unfoldr streamLen2)
537− , benchFold "filterAllOutPure" filterAllOutNested (sourceUnfoldr streamLen2)
607+ , benchFold "filterAllOutMonad (pure)" filterAllOutMonad (unfoldr streamLen2)
538 ]
608 ]
539 where
609 where
540 streamLen2 = round (P.fromIntegral streamLen**(1/2::P.Double)) -- double nested loop
610 streamLen2 = round (P.fromIntegral streamLen**(1/2::P.Double)) -- double nested loop
@@ -543,24 +613,24 @@ o_1_space_nested streamLen =
543o_1_space_transformation :: Int -> Benchmark
613o_1_space_transformation :: Int -> Benchmark
544o_1_space_transformation streamLen =
614o_1_space_transformation streamLen =
545 bgroup "transformation"
615 bgroup "transformation"
546− [ benchFold "foldrS" (foldrS 1) (sourceUnfoldrM streamLen)
616+ [ benchFold "foldrS" (foldrS 1) (unfoldrM streamLen)
547− , benchFold "scan" (scan 1) (sourceUnfoldrM streamLen)
617+ , benchFold "scanl'" (scanl' 1) (unfoldrM streamLen)
548− , benchFold "map" (map 1) (sourceUnfoldrM streamLen)
618+ , benchFold "map" (map 1) (unfoldrM streamLen)
549− , benchFold "fmap" (fmapK 1) (sourceUnfoldrM streamLen)
619+ , benchFold "fmap" (fmapK 1) (unfoldrM streamLen)
550− , benchFold "mapM" (mapM 1) (sourceUnfoldrM streamLen)
620+ , benchFold "mapM" (mapM 1) (unfoldrM streamLen)
551− , benchFold "mapMSerial" (mapMSerial 1) (sourceUnfoldrM streamLen)
621+ , benchFold "mapMSerial" (mapMSerial 1) (unfoldrM streamLen)
552 ]
622 ]
553
623
554o_1_space_transformationX4 :: Int -> Benchmark
624o_1_space_transformationX4 :: Int -> Benchmark
555o_1_space_transformationX4 streamLen =
625o_1_space_transformationX4 streamLen =
556 bgroup "transformationX4"
626 bgroup "transformationX4"
557− [ benchFold "scan" (scan 4) (sourceUnfoldrM streamLen)
627+ [ benchFold "scanl'" (scanl' 4) (unfoldrM streamLen)
558− , benchFold "map" (map 4) (sourceUnfoldrM streamLen)
628+ , benchFold "map" (map 4) (unfoldrM streamLen)
559− , benchFold "fmap" (fmapK 4) (sourceUnfoldrM streamLen)
629+ , benchFold "fmap" (fmapK 4) (unfoldrM streamLen)
560− , benchFold "mapM" (mapM 4) (sourceUnfoldrM streamLen)
630+ , benchFold "mapM" (mapM 4) (unfoldrM streamLen)
561− , benchFold "mapMSerial" (mapMSerial 4) (sourceUnfoldrM streamLen)
631+ , benchFold "mapMSerial" (mapMSerial 4) (unfoldrM streamLen)
562 -- XXX this is horribly slow
632 -- XXX this is horribly slow
563− -- , benchFold "concatMap" (concatMap 4) (sourceUnfoldrM streamLen16)
633+ -- , benchFold "concatMap" (concatMap 4) (unfoldrM streamLen16)
564 ]
634 ]
565
635
566o_1_space_concat :: Int -> Benchmark
636o_1_space_concat :: Int -> Benchmark
@@ -587,12 +657,12 @@ o_1_space_concat streamLen =
587 , benchIOSrc1 "concatMapWithId (n of 1) (fromFoldable)"
657 , benchIOSrc1 "concatMapWithId (n of 1) (fromFoldable)"
588 (S.drain . S.concatMapBy S.serial id . sourceConcatMapId streamLen)
658 (S.drain . S.concatMapBy S.serial id . sourceConcatMapId streamLen)
589
659
590− , benchIOSrc1 "concatMapWith (n of 1)"
660+ , benchIOSrc1 "concatMapBy serial (n of 1)"
591− (concatStreamsWith streamLen 1)
661+ (concatMapBySerial streamLen 1)
592− , benchIOSrc1 "concatMapWith (sqrt n of sqrt n)"
662+ , benchIOSrc1 "concatMapBy serial (sqrt n of sqrt n)"
593− (concatStreamsWith streamLen2 streamLen2)
663+ (concatMapBySerial streamLen2 streamLen2)
594− , benchIOSrc1 "concatMapWith (1 of n)"
664+ , benchIOSrc1 "concatMapBy serial (1 of n)"
595− (concatStreamsWith 1 streamLen)
665+ (concatMapBySerial 1 streamLen)
596 ]
666 ]
597 where
667 where
598 streamLen2 = round (P.fromIntegral streamLen**(1/2::P.Double)) -- double nested loop
668 streamLen2 = round (P.fromIntegral streamLen**(1/2::P.Double)) -- double nested loop
@@ -600,94 +670,94 @@ o_1_space_concat streamLen =
600o_1_space_filtering :: Int -> Benchmark
670o_1_space_filtering :: Int -> Benchmark
601o_1_space_filtering streamLen =
671o_1_space_filtering streamLen =
602 bgroup "filtering"
672 bgroup "filtering"
603− [ benchFold "filter-even" (filterEven 1) (sourceUnfoldrM streamLen)
673+ [ benchFold "filter-even" (filterEven 1) (unfoldrM streamLen)
604− , benchFold "filter-all-out" (filterAllOut streamLen 1) (sourceUnfoldrM streamLen)
674+ , benchFold "filter-all-out" (filterAllOut streamLen 1) (unfoldrM streamLen)
605− , benchFold "filter-all-in" (filterAllIn streamLen 1) (sourceUnfoldrM streamLen)
675+ , benchFold "filter-all-in" (filterAllIn streamLen 1) (unfoldrM streamLen)
606− , benchFold "take-all" (takeAll streamLen 1) (sourceUnfoldrM streamLen)
676+ , benchFold "take-all" (takeAll streamLen 1) (unfoldrM streamLen)
607− , benchFold "takeWhile-true" (takeWhileTrue streamLen 1) (sourceUnfoldrM streamLen)
677+ , benchFold "takeWhile-true" (takeWhileTrue streamLen 1) (unfoldrM streamLen)
608− , benchFold "drop-one" (dropOne 1) (sourceUnfoldrM streamLen)
678+ , benchFold "drop-one" (dropOne 1) (unfoldrM streamLen)
609− , benchFold "drop-all" (dropAll streamLen 1) (sourceUnfoldrM streamLen)
679+ , benchFold "drop-all" (dropAll streamLen 1) (unfoldrM streamLen)
610− , benchFold "dropWhile-true" (dropWhileTrue streamLen 1) (sourceUnfoldrM streamLen)
680+ , benchFold "dropWhile-true" (dropWhileTrue streamLen 1) (unfoldrM streamLen)
611− , benchFold "dropWhile-false" (dropWhileFalse 1) (sourceUnfoldrM streamLen)
681+ , benchFold "dropWhile-false" (dropWhileFalse 1) (unfoldrM streamLen)
612 ]
682 ]
613
683
614o_1_space_filteringX4 :: Int -> Benchmark
684o_1_space_filteringX4 :: Int -> Benchmark
615o_1_space_filteringX4 streamLen =
685o_1_space_filteringX4 streamLen =
616 bgroup "filteringX4"
686 bgroup "filteringX4"
617− [ benchFold "filter-even" (filterEven 4) (sourceUnfoldrM streamLen)
687+ [ benchFold "filter-even" (filterEven 4) (unfoldrM streamLen)
618− , benchFold "filter-all-out" (filterAllOut streamLen 4) (sourceUnfoldrM streamLen)
688+ , benchFold "filter-all-out" (filterAllOut streamLen 4) (unfoldrM streamLen)
619− , benchFold "filter-all-in" (filterAllIn streamLen 4) (sourceUnfoldrM streamLen)
689+ , benchFold "filter-all-in" (filterAllIn streamLen 4) (unfoldrM streamLen)
620− , benchFold "take-all" (takeAll streamLen 4) (sourceUnfoldrM streamLen)
690+ , benchFold "take-all" (takeAll streamLen 4) (unfoldrM streamLen)
621− , benchFold "takeWhile-true" (takeWhileTrue streamLen 4) (sourceUnfoldrM streamLen)
691+ , benchFold "takeWhile-true" (takeWhileTrue streamLen 4) (unfoldrM streamLen)
622− , benchFold "drop-one" (dropOne 4) (sourceUnfoldrM streamLen)
692+ , benchFold "drop-one" (dropOne 4) (unfoldrM streamLen)
623− , benchFold "drop-all" (dropAll streamLen 4) (sourceUnfoldrM streamLen)
693+ , benchFold "drop-all" (dropAll streamLen 4) (unfoldrM streamLen)
624− , benchFold "dropWhile-true" (dropWhileTrue streamLen 4) (sourceUnfoldrM streamLen)
694+ , benchFold "dropWhile-true" (dropWhileTrue streamLen 4) (unfoldrM streamLen)
625− , benchFold "dropWhile-false" (dropWhileFalse 4) (sourceUnfoldrM streamLen)
695+ , benchFold "dropWhile-false" (dropWhileFalse 4) (unfoldrM streamLen)
626 ]
696 ]
627
697
628o_1_space_zipping :: Int -> Benchmark
698o_1_space_zipping :: Int -> Benchmark
629o_1_space_zipping streamLen =
699o_1_space_zipping streamLen =
630 bgroup "zipping"
700 bgroup "zipping"
631− [ benchFold "zip" zip (sourceUnfoldrM streamLen)
701+ [ benchFold "zipWith" zipWith (unfoldrM streamLen)
632 ]
702 ]
633
703
634o_1_space_mixed :: Int -> Benchmark
704o_1_space_mixed :: Int -> Benchmark
635o_1_space_mixed streamLen =
705o_1_space_mixed streamLen =
636 bgroup "mixed"
706 bgroup "mixed"
637− [ benchFold "scan-map" (scanMap 1) (sourceUnfoldrM streamLen)
707+ [ benchFold "scan-map" (scanMap 1) (unfoldrM streamLen)
638− , benchFold "drop-map" (dropMap 1) (sourceUnfoldrM streamLen)
708+ , benchFold "drop-map" (dropMap 1) (unfoldrM streamLen)
639− , benchFold "drop-scan" (dropScan 1) (sourceUnfoldrM streamLen)
709+ , benchFold "drop-scan" (dropScan 1) (unfoldrM streamLen)
640− , benchFold "take-drop" (takeDrop streamLen 1) (sourceUnfoldrM streamLen)
710+ , benchFold "take-drop" (takeDrop streamLen 1) (unfoldrM streamLen)
641− , benchFold "take-scan" (takeScan streamLen 1) (sourceUnfoldrM streamLen)
711+ , benchFold "take-scan" (takeScan streamLen 1) (unfoldrM streamLen)
642− , benchFold "take-map" (takeMap streamLen 1) (sourceUnfoldrM streamLen)
712+ , benchFold "take-map" (takeMap streamLen 1) (unfoldrM streamLen)
643− , benchFold "filter-drop" (filterDrop streamLen 1) (sourceUnfoldrM streamLen)
713+ , benchFold "filter-drop" (filterDrop streamLen 1) (unfoldrM streamLen)
644− , benchFold "filter-take" (filterTake streamLen 1) (sourceUnfoldrM streamLen)
714+ , benchFold "filter-take" (filterTake streamLen 1) (unfoldrM streamLen)
645− , benchFold "filter-scan" (filterScan 1) (sourceUnfoldrM streamLen)
715+ , benchFold "filter-scan" (filterScan 1) (unfoldrM streamLen)
646− , benchFold "filter-map" (filterMap streamLen 1) (sourceUnfoldrM streamLen)
716+ , benchFold "filter-map" (filterMap streamLen 1) (unfoldrM streamLen)
647 ]
717 ]
648
718
649o_1_space_mixedX2 :: Int -> Benchmark
719o_1_space_mixedX2 :: Int -> Benchmark
650o_1_space_mixedX2 streamLen =
720o_1_space_mixedX2 streamLen =
651 bgroup "mixedX2"
721 bgroup "mixedX2"
652− [ benchFold "scan-map" (scanMap 2) (sourceUnfoldrM streamLen)
722+ [ benchFold "scan-map" (scanMap 2) (unfoldrM streamLen)
653− , benchFold "drop-map" (dropMap 2) (sourceUnfoldrM streamLen)
723+ , benchFold "drop-map" (dropMap 2) (unfoldrM streamLen)
654− , benchFold "drop-scan" (dropScan 2) (sourceUnfoldrM streamLen)
724+ , benchFold "drop-scan" (dropScan 2) (unfoldrM streamLen)
655− , benchFold "take-drop" (takeDrop streamLen 2) (sourceUnfoldrM streamLen)
725+ , benchFold "take-drop" (takeDrop streamLen 2) (unfoldrM streamLen)
656− , benchFold "take-scan" (takeScan streamLen 2) (sourceUnfoldrM streamLen)
726+ , benchFold "take-scan" (takeScan streamLen 2) (unfoldrM streamLen)
657− , benchFold "take-map" (takeMap streamLen 2) (sourceUnfoldrM streamLen)
727+ , benchFold "take-map" (takeMap streamLen 2) (unfoldrM streamLen)
658− , benchFold "filter-drop" (filterDrop streamLen 2) (sourceUnfoldrM streamLen)
728+ , benchFold "filter-drop" (filterDrop streamLen 2) (unfoldrM streamLen)
659− , benchFold "filter-take" (filterTake streamLen 2) (sourceUnfoldrM streamLen)
729+ , benchFold "filter-take" (filterTake streamLen 2) (unfoldrM streamLen)
660− , benchFold "filter-scan" (filterScan 2) (sourceUnfoldrM streamLen)
730+ , benchFold "filter-scan" (filterScan 2) (unfoldrM streamLen)
661− , benchFold "filter-map" (filterMap streamLen 2) (sourceUnfoldrM streamLen)
731+ , benchFold "filter-map" (filterMap streamLen 2) (unfoldrM streamLen)
662 ]
732 ]
663
733
664o_1_space_mixedX4 :: Int -> Benchmark
734o_1_space_mixedX4 :: Int -> Benchmark
665o_1_space_mixedX4 streamLen =
735o_1_space_mixedX4 streamLen =
666 bgroup "mixedX4"
736 bgroup "mixedX4"
667− [ benchFold "scan-map" (scanMap 4) (sourceUnfoldrM streamLen)
737+ [ benchFold "scan-map" (scanMap 4) (unfoldrM streamLen)
668− , benchFold "drop-map" (dropMap 4) (sourceUnfoldrM streamLen)
738+ , benchFold "drop-map" (dropMap 4) (unfoldrM streamLen)
669− , benchFold "drop-scan" (dropScan 4) (sourceUnfoldrM streamLen)
739+ , benchFold "drop-scan" (dropScan 4) (unfoldrM streamLen)
670− , benchFold "take-drop" (takeDrop streamLen 4) (sourceUnfoldrM streamLen)
740+ , benchFold "take-drop" (takeDrop streamLen 4) (unfoldrM streamLen)
671− , benchFold "take-scan" (takeScan streamLen 4) (sourceUnfoldrM streamLen)
741+ , benchFold "take-scan" (takeScan streamLen 4) (unfoldrM streamLen)
672− , benchFold "take-map" (takeMap streamLen 4) (sourceUnfoldrM streamLen)
742+ , benchFold "take-map" (takeMap streamLen 4) (unfoldrM streamLen)
673− , benchFold "filter-drop" (filterDrop streamLen 4) (sourceUnfoldrM streamLen)
743+ , benchFold "filter-drop" (filterDrop streamLen 4) (unfoldrM streamLen)
674− , benchFold "filter-take" (filterTake streamLen 4) (sourceUnfoldrM streamLen)
744+ , benchFold "filter-take" (filterTake streamLen 4) (unfoldrM streamLen)
675− , benchFold "filter-scan" (filterScan 4) (sourceUnfoldrM streamLen)
745+ , benchFold "filter-scan" (filterScan 4) (unfoldrM streamLen)
676− , benchFold "filter-map" (filterMap streamLen 4) (sourceUnfoldrM streamLen)
746+ , benchFold "filter-map" (filterMap streamLen 4) (unfoldrM streamLen)
677 ]
747 ]
678
748
679o_1_space_list :: Int -> Benchmark
749o_1_space_list :: Int -> Benchmark
680o_1_space_list streamLen =
750o_1_space_list streamLen =
681 bgroup "list"
751 bgroup "list"
682 [ bgroup "elimination"
752 [ bgroup "elimination"
683− [ benchList "last" (\xs -> [List.last xs]) (sourceUnfoldrList streamLen)
753+ [ benchList "last" (\xs -> [List.last xs]) (unfoldrList streamLen)
684 ]
754 ]
685 , bgroup "nested"
755 , bgroup "nested"
686− [ benchList "toNullAp" toNullApNestedList (sourceUnfoldrList streamLen2)
756+ [ benchList "toNullAp" toNullApNestedList (unfoldrList streamLen2)
687− , benchList "toNull" toNullNestedList (sourceUnfoldrList streamLen2)
757+ , benchList "toNull" toNullNestedList (unfoldrList streamLen2)
688− , benchList "toNull3" toNullNestedList3 (sourceUnfoldrList streamLen3)
758+ , benchList "toNull3" toNullNestedList3 (unfoldrList streamLen3)
689− , benchList "filterAllIn" filterAllInNestedList (sourceUnfoldrList streamLen2)
759+ , benchList "filterAllIn" filterAllInNestedList (unfoldrList streamLen2)
690− , benchList "filterAllOut" filterAllOutNestedList (sourceUnfoldrList streamLen2)
760+ , benchList "filterAllOut" filterAllOutNestedList (unfoldrList streamLen2)
691 ]
761 ]
692 ]
762 ]
693 where
763 where
@@ -717,31 +787,31 @@ o_n_heap :: Int -> Benchmark
717o_n_heap streamLen =
787o_n_heap streamLen =
718 bgroup (o_n_heap_prefix moduleName)
788 bgroup (o_n_heap_prefix moduleName)
719 [ bgroup "transformation"
789 [ bgroup "transformation"
720− [ benchFold "foldlS" (foldlS 1) (sourceUnfoldrM streamLen)
790+ [ benchFold "foldlS" (foldlS 1) (unfoldrM streamLen)
721 ]
791 ]
722 ]
792 ]
723
793
724{-# INLINE benchK #-}
794{-# INLINE benchK #-}
725benchK :: P.String -> (Int -> Stream P.IO Int) -> Benchmark
795benchK :: P.String -> (Int -> Stream P.IO Int) -> Benchmark
726−benchK name f = bench name $ nfIO $ randomRIO (1,1) >>= toNull . f
796+benchK name f = bench name $ nfIO $ randomRIO (1,1) >>= drain . f
727
797
728o_n_stack :: Int -> Int -> Int -> Benchmark
798o_n_stack :: Int -> Int -> Int -> Benchmark
729o_n_stack streamLen iterStreamLen maxIters =
799o_n_stack streamLen iterStreamLen maxIters =
730 bgroup (o_n_stack_prefix moduleName)
800 bgroup (o_n_stack_prefix moduleName)
731 [ bgroup "elimination"
801 [ bgroup "elimination"
732− [ benchFold "tail" tail (sourceUnfoldrM streamLen)
802+ [ benchFold "tail" tail (unfoldrM streamLen)
733− , benchFold "nullTail" nullTail (sourceUnfoldrM streamLen)
803+ , benchFold "nullTail" nullTail (unfoldrM streamLen)
734− , benchFold "headTail" headTail (sourceUnfoldrM streamLen)
804+ , benchFold "headTail" headTail (unfoldrM streamLen)
735 ]
805 ]
736 , bgroup "transformation"
806 , bgroup "transformation"
737 [
807 [
738 -- XXX why do these need so much stack
808 -- XXX why do these need so much stack
739− benchFold "intersperse" (intersperse streamLen 1) (sourceUnfoldrM streamLen2)
809+ benchFold "intersperse" (intersperse streamLen 1) (unfoldrM streamLen2)
740− , benchFold "interspersePure" (intersperse streamLen 1) (sourceUnfoldr streamLen2)
810+ , benchFold "interspersePure" (intersperse streamLen 1) (unfoldr streamLen2)
741 ]
811 ]
742 , bgroup "transformationX4"
812 , bgroup "transformationX4"
743 [
813 [
744− benchFold "intersperse" (intersperse streamLen 4) (sourceUnfoldrM streamLen16)
814+ benchFold "intersperse" (intersperse streamLen 4) (unfoldrM streamLen16)
745 ]
815 ]
746 , bgroup "iterated"
816 , bgroup "iterated"
747 [ benchK "mapM" (iterateMapM iterStreamLen maxIters)
817 [ benchK "mapM" (iterateMapM iterStreamLen maxIters)
@@ -761,7 +831,7 @@ o_n_space :: Int -> Benchmark
761o_n_space streamLen =
831o_n_space streamLen =
762 bgroup (o_n_space_prefix moduleName)
832 bgroup (o_n_space_prefix moduleName)
763 [ bgroup "elimination"
833 [ bgroup "elimination"
764− [ benchFold "toList" toList (sourceUnfoldrM streamLen)
834+ [ benchFold "toList" toList (unfoldrM streamLen)
765 ]
835 ]
766 ]
836 ]
767
837