on master help sign in
Rename value-ish to streamLen-ish in bench:StreamK
98bc69eAdithya Kumar
benchmark/Streamly/Benchmark/Data/Stream/StreamK.hs+174−182
@@ -48,30 +48,30 @@ type Stream m a = S.Stream m a
48
48
49{-# INLINE sourceUnfoldr #-}
49{-# INLINE sourceUnfoldr #-}
50sourceUnfoldr :: Int -> Int -> Stream m Int
50sourceUnfoldr :: Int -> Int -> Stream m Int
51−sourceUnfoldr value n = S.unfoldr step n
51+sourceUnfoldr streamLen n = S.unfoldr step n
52 where
52 where
53 step cnt =
53 step cnt =
54− if cnt > n + value
54+ if cnt > n + streamLen
55 then Nothing
55 then Nothing
56 else Just (cnt, cnt + 1)
56 else Just (cnt, cnt + 1)
57
57
58{-# INLINE sourceUnfoldrM #-}
58{-# INLINE sourceUnfoldrM #-}
59sourceUnfoldrM :: S.MonadAsync m => Int -> Int -> Stream m Int
59sourceUnfoldrM :: S.MonadAsync m => Int -> Int -> Stream m Int
60−sourceUnfoldrM value n = S.unfoldrM step n
60+sourceUnfoldrM streamLen n = S.unfoldrM step n
61 where
61 where
62 step cnt =
62 step cnt =
63− if cnt > n + value
63+ if cnt > n + streamLen
64 then return Nothing
64 then return Nothing
65 else return (Just (cnt, cnt + 1))
65 else return (Just (cnt, cnt + 1))
66
66
67{-# INLINE sourceFromFoldable #-}
67{-# INLINE sourceFromFoldable #-}
68sourceFromFoldable :: Int -> Int -> Stream m Int
68sourceFromFoldable :: Int -> Int -> Stream m Int
69−sourceFromFoldable value n = S.fromFoldable [n..n+value]
69+sourceFromFoldable streamLen n = S.fromFoldable [n..n+streamLen]
70
70
71{-# INLINE sourceFromFoldableM #-}
71{-# INLINE sourceFromFoldableM #-}
72sourceFromFoldableM :: S.MonadAsync m => Int -> Int -> Stream m Int
72sourceFromFoldableM :: S.MonadAsync m => Int -> Int -> Stream m Int
73−sourceFromFoldableM value n =
73+sourceFromFoldableM streamLen n =
74− Prelude.foldr S.consM S.nil (Prelude.fmap return [n..n+value])
74+ Prelude.foldr S.consM S.nil (Prelude.fmap return [n..n+streamLen])
75
75
76{-# INLINABLE concatMapFoldableWith #-}
76{-# INLINABLE concatMapFoldableWith #-}
77concatMapFoldableWith :: (S.IsStream t, Foldable f)
77concatMapFoldableWith :: (S.IsStream t, Foldable f)
@@ -80,12 +80,12 @@ concatMapFoldableWith f g = Prelude.foldr (f . g) S.nil
80
80
81{-# INLINE sourceFoldMapWith #-}
81{-# INLINE sourceFoldMapWith #-}
82sourceFoldMapWith :: Int -> Int -> Stream m Int
82sourceFoldMapWith :: Int -> Int -> Stream m Int
83−sourceFoldMapWith value n = concatMapFoldableWith S.serial S.yield [n..n+value]
83+sourceFoldMapWith streamLen n = concatMapFoldableWith S.serial S.yield [n..n+streamLen]
84
84
85{-# INLINE sourceFoldMapWithM #-}
85{-# INLINE sourceFoldMapWithM #-}
86sourceFoldMapWithM :: Monad m => Int -> Int -> Stream m Int
86sourceFoldMapWithM :: Monad m => Int -> Int -> Stream m Int
87−sourceFoldMapWithM value n =
87+sourceFoldMapWithM streamLen n =
88− concatMapFoldableWith S.serial (S.yieldM . return) [n..n+value]
88+ concatMapFoldableWith S.serial (S.yieldM . return) [n..n+streamLen]
89
89
90-------------------------------------------------------------------------------
90-------------------------------------------------------------------------------
91-- Elimination
91-- Elimination
@@ -192,11 +192,11 @@ filterEven n = composeN n $ S.filter even
192
192
193{-# INLINE filterAllOut #-}
193{-# INLINE filterAllOut #-}
194filterAllOut :: Monad m => Int -> Int -> Stream m Int -> m ()
194filterAllOut :: Monad m => Int -> Int -> Stream m Int -> m ()
195−filterAllOut maxValue n = composeN n $ S.filter (> maxValue)
195+filterAllOut streamLen n = composeN n $ S.filter (> streamLen)
196
196
197{-# INLINE filterAllIn #-}
197{-# INLINE filterAllIn #-}
198filterAllIn :: Monad m => Int -> Int -> Stream m Int -> m ()
198filterAllIn :: Monad m => Int -> Int -> Stream m Int -> m ()
199−filterAllIn maxValue n = composeN n $ S.filter (<= maxValue)
199+filterAllIn streamLen n = composeN n $ S.filter (<= streamLen)
200
200
201{-# INLINE _takeOne #-}
201{-# INLINE _takeOne #-}
202_takeOne :: Monad m => Int -> Stream m Int -> m ()
202_takeOne :: Monad m => Int -> Stream m Int -> m ()
@@ -204,11 +204,11 @@ _takeOne n = composeN n $ S.take 1
204
204
205{-# INLINE takeAll #-}
205{-# INLINE takeAll #-}
206takeAll :: Monad m => Int -> Int -> Stream m Int -> m ()
206takeAll :: Monad m => Int -> Int -> Stream m Int -> m ()
207−takeAll maxValue n = composeN n $ S.take maxValue
207+takeAll streamLen n = composeN n $ S.take streamLen
208
208
209{-# INLINE takeWhileTrue #-}
209{-# INLINE takeWhileTrue #-}
210takeWhileTrue :: Monad m => Int -> Int -> Stream m Int -> m ()
210takeWhileTrue :: Monad m => Int -> Int -> Stream m Int -> m ()
211−takeWhileTrue maxValue n = composeN n $ S.takeWhile (<= maxValue)
211+takeWhileTrue streamLen n = composeN n $ S.takeWhile (<= streamLen)
212
212
213{-# INLINE dropOne #-}
213{-# INLINE dropOne #-}
214dropOne :: Monad m => Int -> Stream m Int -> m ()
214dropOne :: Monad m => Int -> Stream m Int -> m ()
@@ -216,11 +216,11 @@ dropOne n = composeN n $ S.drop 1
216
216
217{-# INLINE dropAll #-}
217{-# INLINE dropAll #-}
218dropAll :: Monad m => Int -> Int -> Stream m Int -> m ()
218dropAll :: Monad m => Int -> Int -> Stream m Int -> m ()
219−dropAll maxValue n = composeN n $ S.drop maxValue
219+dropAll streamLen n = composeN n $ S.drop streamLen
220
220
221{-# INLINE dropWhileTrue #-}
221{-# INLINE dropWhileTrue #-}
222dropWhileTrue :: Monad m => Int -> Int -> Stream m Int -> m ()
222dropWhileTrue :: Monad m => Int -> Int -> Stream m Int -> m ()
223−dropWhileTrue maxValue n = composeN n $ S.dropWhile (<= maxValue)
223+dropWhileTrue streamLen n = composeN n $ S.dropWhile (<= streamLen)
224
224
225{-# INLINE dropWhileFalse #-}
225{-# INLINE dropWhileFalse #-}
226dropWhileFalse :: Monad m => Int -> Stream m Int -> m ()
226dropWhileFalse :: Monad m => Int -> Stream m Int -> m ()
@@ -236,7 +236,7 @@ foldlS n = composeN n $ S.foldlS (flip S.cons) S.nil
236
236
237{-# INLINE intersperse #-}
237{-# INLINE intersperse #-}
238intersperse :: S.MonadAsync m => Int -> Int -> Stream m Int -> m ()
238intersperse :: S.MonadAsync m => Int -> Int -> Stream m Int -> m ()
239−intersperse maxValue n = composeN n $ S.intersperse maxValue
239+intersperse streamLen n = composeN n $ S.intersperse streamLen
240
240
241-------------------------------------------------------------------------------
241-------------------------------------------------------------------------------
242-- Iteration
242-- Iteration
@@ -259,8 +259,8 @@ iterateScan iterStreamLen maxIters = iterateSource iterStreamLen (S.scanl' (+) 0
259-- this is quadratic
259-- this is quadratic
260{-# INLINE iterateDropWhileFalse #-}
260{-# INLINE iterateDropWhileFalse #-}
261iterateDropWhileFalse :: S.MonadAsync m => Int -> Int -> Int -> Int -> Stream m Int
261iterateDropWhileFalse :: S.MonadAsync m => Int -> Int -> Int -> Int -> Stream m Int
262−iterateDropWhileFalse maxValue iterStreamLen maxIters =
262+iterateDropWhileFalse streamLen iterStreamLen maxIters =
263− iterateSource iterStreamLen (S.dropWhile (> maxValue)) (maxIters `div` 10)
263+ iterateSource iterStreamLen (S.dropWhile (> streamLen)) (maxIters `div` 10)
264
264
265{-# INLINE iterateMapM #-}
265{-# INLINE iterateMapM #-}
266iterateMapM :: S.MonadAsync m => Int -> Int -> Int -> Stream m Int
266iterateMapM :: S.MonadAsync m => Int -> Int -> Int -> Stream m Int
@@ -272,7 +272,7 @@ iterateFilterEven iterStreamLen maxIters = iterateSource iterStreamLen (S.filter
272
272
273{-# INLINE iterateTakeAll #-}
273{-# INLINE iterateTakeAll #-}
274iterateTakeAll :: S.MonadAsync m => Int -> Int -> Int -> Int -> Stream m Int
274iterateTakeAll :: S.MonadAsync m => Int -> Int -> Int -> Int -> Stream m Int
275−iterateTakeAll maxValue iterStreamLen maxIters = iterateSource iterStreamLen (S.take maxValue) maxIters
275+iterateTakeAll streamLen iterStreamLen maxIters = iterateSource iterStreamLen (S.take streamLen) maxIters
276
276
277{-# INLINE iterateDropOne #-}
277{-# INLINE iterateDropOne #-}
278iterateDropOne :: S.MonadAsync m => Int -> Int -> Int -> Stream m Int
278iterateDropOne :: S.MonadAsync m => Int -> Int -> Int -> Stream m Int
@@ -280,7 +280,7 @@ iterateDropOne iterStreamLen maxIters = iterateSource iterStreamLen (S.drop 1) m
280
280
281{-# INLINE iterateDropWhileTrue #-}
281{-# INLINE iterateDropWhileTrue #-}
282iterateDropWhileTrue :: S.MonadAsync m => Int -> Int -> Int -> Int -> Stream m Int
282iterateDropWhileTrue :: S.MonadAsync m => Int -> Int -> Int -> Int -> Stream m Int
283−iterateDropWhileTrue maxValue iterStreamLen maxIters = iterateSource iterStreamLen (S.dropWhile (<= maxValue)) maxIters
283+iterateDropWhileTrue streamLen iterStreamLen maxIters = iterateSource iterStreamLen (S.dropWhile (<= streamLen)) maxIters
284
284
285-------------------------------------------------------------------------------
285-------------------------------------------------------------------------------
286-- Zipping
286-- Zipping
@@ -308,32 +308,32 @@ dropScan n = composeN n $ S.scanl' (+) 0 . S.drop 1
308
308
309{-# INLINE takeDrop #-}
309{-# INLINE takeDrop #-}
310takeDrop :: Monad m => Int -> Int -> Stream m Int -> m ()
310takeDrop :: Monad m => Int -> Int -> Stream m Int -> m ()
311−takeDrop maxValue n = composeN n $ S.drop 1 . S.take maxValue
311+takeDrop streamLen n = composeN n $ S.drop 1 . S.take streamLen
312
312
313{-# INLINE takeScan #-}
313{-# INLINE takeScan #-}
314takeScan :: Monad m => Int -> Int -> Stream m Int -> m ()
314takeScan :: Monad m => Int -> Int -> Stream m Int -> m ()
315−takeScan maxValue n = composeN n $ S.scanl' (+) 0 . S.take maxValue
315+takeScan streamLen n = composeN n $ S.scanl' (+) 0 . S.take streamLen
316
316
317{-# INLINE takeMap #-}
317{-# INLINE takeMap #-}
318takeMap :: Monad m => Int -> Int -> Stream m Int -> m ()
318takeMap :: Monad m => Int -> Int -> Stream m Int -> m ()
319−takeMap maxValue n = composeN n $ S.map (subtract 1) . S.take maxValue
319+takeMap streamLen n = composeN n $ S.map (subtract 1) . S.take streamLen
320
320
321{-# INLINE filterDrop #-}
321{-# INLINE filterDrop #-}
322filterDrop :: Monad m => Int -> Int -> Stream m Int -> m ()
322filterDrop :: Monad m => Int -> Int -> Stream m Int -> m ()
323−filterDrop maxValue n = composeN n $ S.drop 1 . S.filter (<= maxValue)
323+filterDrop streamLen n = composeN n $ S.drop 1 . S.filter (<= streamLen)
324
324
325{-# INLINE filterTake #-}
325{-# INLINE filterTake #-}
326filterTake :: Monad m => Int -> Int -> Stream m Int -> m ()
326filterTake :: Monad m => Int -> Int -> Stream m Int -> m ()
327−filterTake maxValue n = composeN n $ S.take maxValue . S.filter (<= maxValue)
327+filterTake streamLen n = composeN n $ S.take streamLen . S.filter (<= streamLen)
328
328
329−-- Initially, this used maxBound not maxValue
329+-- Initially, this used maxBound not streamLen
330{-# INLINE filterScan #-}
330{-# INLINE filterScan #-}
331filterScan :: Monad m => Int -> Int -> Stream m Int -> m ()
331filterScan :: Monad m => Int -> Int -> Stream m Int -> m ()
332−filterScan maxValue n = composeN n $ S.scanl' (+) 0 . S.filter (<= maxValue)
332+filterScan streamLen n = composeN n $ S.scanl' (+) 0 . S.filter (<= streamLen)
333
333
334{-# INLINE filterMap #-}
334{-# INLINE filterMap #-}
335filterMap :: Monad m => Int -> Int -> Stream m Int -> m ()
335filterMap :: Monad m => Int -> Int -> Stream m Int -> m ()
336−filterMap maxValue n = composeN n $ S.map (subtract 1) . S.filter (<= maxValue)
336+filterMap streamLen n = composeN n $ S.map (subtract 1) . S.filter (<= streamLen)
337
337
338-------------------------------------------------------------------------------
338-------------------------------------------------------------------------------
339-- ConcatMap
339-- ConcatMap
@@ -499,223 +499,216 @@ moduleName :: String
499moduleName = "Data.Stream.StreamK"
499moduleName = "Data.Stream.StreamK"
500
500
501o_1_space_generation :: Int -> Benchmark
501o_1_space_generation :: Int -> Benchmark
502−o_1_space_generation value =
502+o_1_space_generation streamLen =
503 bgroup "generation"
503 bgroup "generation"
504− [ benchFold "unfoldr" toNull (sourceUnfoldr value)
504+ [ benchFold "unfoldr" toNull (sourceUnfoldr streamLen)
505− , benchFold "unfoldrM" toNull (sourceUnfoldrM value)
505+ , benchFold "unfoldrM" toNull (sourceUnfoldrM streamLen)
506
506
507− , benchFold "fromFoldable" toNull (sourceFromFoldable value)
507+ , benchFold "fromFoldable" toNull (sourceFromFoldable streamLen)
508− , benchFold "fromFoldableM" toNull (sourceFromFoldableM value)
508+ , benchFold "fromFoldableM" toNull (sourceFromFoldableM streamLen)
509
509
510 -- appends
510 -- appends
511− , benchFold "concatMapFoldableWith" toNull (sourceFoldMapWith value)
511+ , benchFold "concatMapFoldableWith" toNull (sourceFoldMapWith streamLen)
512− , benchFold "concatMapFoldableWithM" toNull (sourceFoldMapWithM value)
512+ , benchFold "concatMapFoldableWithM" toNull (sourceFoldMapWithM streamLen)
513 ]
513 ]
514
514
515o_1_space_elimination :: Int -> Benchmark
515o_1_space_elimination :: Int -> Benchmark
516−o_1_space_elimination value =
516+o_1_space_elimination streamLen =
517 bgroup "elimination"
517 bgroup "elimination"
518− [ benchFold "toNull" toNull (sourceUnfoldrM value)
518+ [ benchFold "toNull" toNull (sourceUnfoldrM streamLen)
519− , benchFold "mapM_" mapM_ (sourceUnfoldrM value)
519+ , benchFold "mapM_" mapM_ (sourceUnfoldrM streamLen)
520− , benchFold "uncons" uncons (sourceUnfoldrM value)
520+ , benchFold "uncons" uncons (sourceUnfoldrM streamLen)
521− , benchFold "init" init (sourceUnfoldrM value)
521+ , benchFold "init" init (sourceUnfoldrM streamLen)
522− , benchFold "foldl'" foldl (sourceUnfoldrM value)
522+ , benchFold "foldl'" foldl (sourceUnfoldrM streamLen)
523− , benchFold "last" last (sourceUnfoldrM value)
523+ , benchFold "last" last (sourceUnfoldrM streamLen)
524 ]
524 ]
525
525
526o_1_space_nested :: Int -> Benchmark
526o_1_space_nested :: Int -> Benchmark
527−o_1_space_nested value =
527+o_1_space_nested streamLen =
528 bgroup "nested"
528 bgroup "nested"
529− [ benchFold "toNullAp" toNullApNested (sourceUnfoldrM value2)
529+ [ benchFold "toNullAp" toNullApNested (sourceUnfoldrM streamLen2)
530− , benchFold "toNull" toNullNested (sourceUnfoldrM value2)
530+ , benchFold "toNull" toNullNested (sourceUnfoldrM streamLen2)
531− , benchFold "toNull3" toNullNested3 (sourceUnfoldrM value3)
531+ , benchFold "toNull3" toNullNested3 (sourceUnfoldrM streamLen3)
532− , benchFold "filterAllIn" filterAllInNested (sourceUnfoldrM value2)
532+ , benchFold "filterAllIn" filterAllInNested (sourceUnfoldrM streamLen2)
533− , benchFold "filterAllOut" filterAllOutNested (sourceUnfoldrM value2)
533+ , benchFold "filterAllOut" filterAllOutNested (sourceUnfoldrM streamLen2)
534− , benchFold "toNullApPure" toNullApNested (sourceUnfoldr value2)
534+ , benchFold "toNullApPure" toNullApNested (sourceUnfoldr streamLen2)
535− , benchFold "toNullPure" toNullNested (sourceUnfoldr value2)
535+ , benchFold "toNullPure" toNullNested (sourceUnfoldr streamLen2)
536− , benchFold "toNull3Pure" toNullNested3 (sourceUnfoldr value3)
536+ , benchFold "toNull3Pure" toNullNested3 (sourceUnfoldr streamLen3)
537− , benchFold "filterAllInPure" filterAllInNested (sourceUnfoldr value2)
537+ , benchFold "filterAllInPure" filterAllInNested (sourceUnfoldr streamLen2)
538− , benchFold "filterAllOutPure" filterAllOutNested (sourceUnfoldr value2)
538+ , benchFold "filterAllOutPure" filterAllOutNested (sourceUnfoldr streamLen2)
539 ]
539 ]
540 where
540 where
541− value2 = round (P.fromIntegral value**(1/2::P.Double)) -- double nested loop
541+ streamLen2 = round (P.fromIntegral streamLen**(1/2::P.Double)) -- double nested loop
542− value3 = round (P.fromIntegral value**(1/3::P.Double)) -- triple nested loop
542+ streamLen3 = round (P.fromIntegral streamLen**(1/3::P.Double)) -- triple nested loop
543
543
544o_1_space_transformation :: Int -> Benchmark
544o_1_space_transformation :: Int -> Benchmark
545−o_1_space_transformation value =
545+o_1_space_transformation streamLen =
546 bgroup "transformation"
546 bgroup "transformation"
547 [ bgroup "X1"
547 [ bgroup "X1"
548− [ benchFold "foldrS" (foldrS 1) (sourceUnfoldrM value)
548+ [ benchFold "foldrS" (foldrS 1) (sourceUnfoldrM streamLen)
549− , benchFold "scan" (scan 1) (sourceUnfoldrM value)
549+ , benchFold "scan" (scan 1) (sourceUnfoldrM streamLen)
550− , benchFold "map" (map 1) (sourceUnfoldrM value)
550+ , benchFold "map" (map 1) (sourceUnfoldrM streamLen)
551− , benchFold "fmap" (fmapK 1) (sourceUnfoldrM value)
551+ , benchFold "fmap" (fmapK 1) (sourceUnfoldrM streamLen)
552− , benchFold "mapM" (mapM 1) (sourceUnfoldrM value)
552+ , benchFold "mapM" (mapM 1) (sourceUnfoldrM streamLen)
553− , benchFold "mapMSerial" (mapMSerial 1) (sourceUnfoldrM value)
553+ , benchFold "mapMSerial" (mapMSerial 1) (sourceUnfoldrM streamLen)
554 ]
554 ]
555 , bgroup "X4"
555 , bgroup "X4"
556− [ benchFold "scan" (scan 4) (sourceUnfoldrM value)
556+ [ benchFold "scan" (scan 4) (sourceUnfoldrM streamLen)
557− , benchFold "map" (map 4) (sourceUnfoldrM value)
557+ , benchFold "map" (map 4) (sourceUnfoldrM streamLen)
558− , benchFold "fmap" (fmapK 4) (sourceUnfoldrM value)
558+ , benchFold "fmap" (fmapK 4) (sourceUnfoldrM streamLen)
559− , benchFold "mapM" (mapM 4) (sourceUnfoldrM value)
559+ , benchFold "mapM" (mapM 4) (sourceUnfoldrM streamLen)
560− , benchFold "mapMSerial" (mapMSerial 4) (sourceUnfoldrM value)
560+ , benchFold "mapMSerial" (mapMSerial 4) (sourceUnfoldrM streamLen)
561 -- XXX this is horribly slow
561 -- XXX this is horribly slow
562− -- , benchFold "concatMap" (concatMap 4) (sourceUnfoldrM value16)
562+ -- , benchFold "concatMap" (concatMap 4) (sourceUnfoldrM streamLen16)
563 ]
563 ]
564 ]
564 ]
565
565
566o_1_space_concat :: Int -> Benchmark
566o_1_space_concat :: Int -> Benchmark
567−o_1_space_concat value =
567+o_1_space_concat streamLen =
568 bgroup "concat"
568 bgroup "concat"
569 [ benchIOSrc1 "concatMapPure (n of 1)"
569 [ benchIOSrc1 "concatMapPure (n of 1)"
570− (concatMapPure value 1)
570+ (concatMapPure streamLen 1)
571 , benchIOSrc1 "concatMapPure (sqrt n of sqrt n)"
571 , benchIOSrc1 "concatMapPure (sqrt n of sqrt n)"
572− (concatMapPure value2 value2)
572+ (concatMapPure streamLen2 streamLen2)
573 , benchIOSrc1 "concatMapPure (1 of n)"
573 , benchIOSrc1 "concatMapPure (1 of n)"
574− (concatMapPure 1 value)
574+ (concatMapPure 1 streamLen)
575
575
576 , benchIOSrc1 "concatMap (n of 1)"
576 , benchIOSrc1 "concatMap (n of 1)"
577− (concatMap value 1)
577+ (concatMap streamLen 1)
578 , benchIOSrc1 "concatMap (sqrt n of sqrt n)"
578 , benchIOSrc1 "concatMap (sqrt n of sqrt n)"
579− (concatMap value2 value2)
579+ (concatMap streamLen2 streamLen2)
580 , benchIOSrc1 "concatMap (1 of n)"
580 , benchIOSrc1 "concatMap (1 of n)"
581− (concatMap 1 value)
581+ (concatMap 1 streamLen)
582
582
583 , benchIOSrc1 "concatMapRepl (sqrt n of sqrt n)"
583 , benchIOSrc1 "concatMapRepl (sqrt n of sqrt n)"
584− (concatMapRepl value2 value2)
584+ (concatMapRepl streamLen2 streamLen2)
585
585
586 -- This is for comparison with concatMapFoldableWith
586 -- This is for comparison with concatMapFoldableWith
587 , benchIOSrc1 "concatMapWithId (n of 1) (fromFoldable)"
587 , benchIOSrc1 "concatMapWithId (n of 1) (fromFoldable)"
588− (S.drain . S.concatMapBy S.serial id . sourceConcatMapId value)
588+ (S.drain . S.concatMapBy S.serial id . sourceConcatMapId streamLen)
589
589
590 , benchIOSrc1 "concatMapWith (n of 1)"
590 , benchIOSrc1 "concatMapWith (n of 1)"
591− (concatStreamsWith value 1)
591+ (concatStreamsWith streamLen 1)
592 , benchIOSrc1 "concatMapWith (sqrt n of sqrt n)"
592 , benchIOSrc1 "concatMapWith (sqrt n of sqrt n)"
593− (concatStreamsWith value2 value2)
593+ (concatStreamsWith streamLen2 streamLen2)
594 , benchIOSrc1 "concatMapWith (1 of n)"
594 , benchIOSrc1 "concatMapWith (1 of n)"
595− (concatStreamsWith 1 value)
595+ (concatStreamsWith 1 streamLen)
596 ]
596 ]
597 where
597 where
598− value2 = round (P.fromIntegral value**(1/2::P.Double)) -- double nested loop
598+ streamLen2 = round (P.fromIntegral streamLen**(1/2::P.Double)) -- double nested loop
599
599
600o_1_space_filtering :: Int -> Benchmark
600o_1_space_filtering :: Int -> Benchmark
601−o_1_space_filtering value =
601+o_1_space_filtering streamLen =
602 bgroup "filtering"
602 bgroup "filtering"
603 [ bgroup "X1"
603 [ bgroup "X1"
604− [ benchFold "filter-even" (filterEven 1) (sourceUnfoldrM value)
604+ [ benchFold "filter-even" (filterEven 1) (sourceUnfoldrM streamLen)
605− , benchFold "filter-all-out" (filterAllOut maxValue 1) (sourceUnfoldrM value)
605+ , benchFold "filter-all-out" (filterAllOut streamLen 1) (sourceUnfoldrM streamLen)
606− , benchFold "filter-all-in" (filterAllIn maxValue 1) (sourceUnfoldrM value)
606+ , benchFold "filter-all-in" (filterAllIn streamLen 1) (sourceUnfoldrM streamLen)
607− , benchFold "take-all" (takeAll maxValue 1) (sourceUnfoldrM value)
607+ , benchFold "take-all" (takeAll streamLen 1) (sourceUnfoldrM streamLen)
608− , benchFold "takeWhile-true" (takeWhileTrue maxValue 1) (sourceUnfoldrM value)
608+ , benchFold "takeWhile-true" (takeWhileTrue streamLen 1) (sourceUnfoldrM streamLen)
609− , benchFold "drop-one" (dropOne 1) (sourceUnfoldrM value)
609+ , benchFold "drop-one" (dropOne 1) (sourceUnfoldrM streamLen)
610− , benchFold "drop-all" (dropAll maxValue 1) (sourceUnfoldrM value)
610+ , benchFold "drop-all" (dropAll streamLen 1) (sourceUnfoldrM streamLen)
611− , benchFold "dropWhile-true" (dropWhileTrue maxValue 1) (sourceUnfoldrM value)
611+ , benchFold "dropWhile-true" (dropWhileTrue streamLen 1) (sourceUnfoldrM streamLen)
612− , benchFold "dropWhile-false" (dropWhileFalse 1) (sourceUnfoldrM value)
612+ , benchFold "dropWhile-false" (dropWhileFalse 1) (sourceUnfoldrM streamLen)
613 ]
613 ]
614 , bgroup "X4"
614 , bgroup "X4"
615− [ benchFold "filter-even" (filterEven 4) (sourceUnfoldrM value)
615+ [ benchFold "filter-even" (filterEven 4) (sourceUnfoldrM streamLen)
616− , benchFold "filter-all-out" (filterAllOut maxValue 4) (sourceUnfoldrM value)
616+ , benchFold "filter-all-out" (filterAllOut streamLen 4) (sourceUnfoldrM streamLen)
617− , benchFold "filter-all-in" (filterAllIn maxValue 4) (sourceUnfoldrM value)
617+ , benchFold "filter-all-in" (filterAllIn streamLen 4) (sourceUnfoldrM streamLen)
618− , benchFold "take-all" (takeAll maxValue 4) (sourceUnfoldrM value)
618+ , benchFold "take-all" (takeAll streamLen 4) (sourceUnfoldrM streamLen)
619− , benchFold "takeWhile-true" (takeWhileTrue maxValue 4) (sourceUnfoldrM value)
619+ , benchFold "takeWhile-true" (takeWhileTrue streamLen 4) (sourceUnfoldrM streamLen)
620− , benchFold "drop-one" (dropOne 4) (sourceUnfoldrM value)
620+ , benchFold "drop-one" (dropOne 4) (sourceUnfoldrM streamLen)
621− , benchFold "drop-all" (dropAll maxValue 4) (sourceUnfoldrM value)
621+ , benchFold "drop-all" (dropAll streamLen 4) (sourceUnfoldrM streamLen)
622− , benchFold "dropWhile-true" (dropWhileTrue maxValue 4) (sourceUnfoldrM value)
622+ , benchFold "dropWhile-true" (dropWhileTrue streamLen 4) (sourceUnfoldrM streamLen)
623− , benchFold "dropWhile-false" (dropWhileFalse 4) (sourceUnfoldrM value)
623+ , benchFold "dropWhile-false" (dropWhileFalse 4) (sourceUnfoldrM streamLen)
624 ]
624 ]
625 ]
625 ]
626− where
627−
628− maxValue = value
629−
630
626
631o_1_space_zipping :: Int -> Benchmark
627o_1_space_zipping :: Int -> Benchmark
632−o_1_space_zipping value =
628+o_1_space_zipping streamLen =
633 bgroup "zipping"
629 bgroup "zipping"
634− [ benchFold "zip" zip (sourceUnfoldrM value)
630+ [ benchFold "zip" zip (sourceUnfoldrM streamLen)
635 ]
631 ]
636
632
637o_1_space_mixed :: Int -> Benchmark
633o_1_space_mixed :: Int -> Benchmark
638−o_1_space_mixed value =
634+o_1_space_mixed streamLen =
639 bgroup "mixed"
635 bgroup "mixed"
640 [ bgroup "X1"
636 [ bgroup "X1"
641− [ benchFold "scan-map" (scanMap 1) (sourceUnfoldrM value)
637+ [ benchFold "scan-map" (scanMap 1) (sourceUnfoldrM streamLen)
642− , benchFold "drop-map" (dropMap 1) (sourceUnfoldrM value)
638+ , benchFold "drop-map" (dropMap 1) (sourceUnfoldrM streamLen)
643− , benchFold "drop-scan" (dropScan 1) (sourceUnfoldrM value)
639+ , benchFold "drop-scan" (dropScan 1) (sourceUnfoldrM streamLen)
644− , benchFold "take-drop" (takeDrop maxValue 1) (sourceUnfoldrM value)
640+ , benchFold "take-drop" (takeDrop streamLen 1) (sourceUnfoldrM streamLen)
645− , benchFold "take-scan" (takeScan maxValue 1) (sourceUnfoldrM value)
641+ , benchFold "take-scan" (takeScan streamLen 1) (sourceUnfoldrM streamLen)
646− , benchFold "take-map" (takeMap maxValue 1) (sourceUnfoldrM value)
642+ , benchFold "take-map" (takeMap streamLen 1) (sourceUnfoldrM streamLen)
647− , benchFold "filter-drop" (filterDrop maxValue 1) (sourceUnfoldrM value)
643+ , benchFold "filter-drop" (filterDrop streamLen 1) (sourceUnfoldrM streamLen)
648− , benchFold "filter-take" (filterTake maxValue 1) (sourceUnfoldrM value)
644+ , benchFold "filter-take" (filterTake streamLen 1) (sourceUnfoldrM streamLen)
649− , benchFold "filter-scan" (filterScan maxValue 1) (sourceUnfoldrM value)
645+ , benchFold "filter-scan" (filterScan streamLen 1) (sourceUnfoldrM streamLen)
650− , benchFold "filter-map" (filterMap maxValue 1) (sourceUnfoldrM value)
646+ , benchFold "filter-map" (filterMap streamLen 1) (sourceUnfoldrM streamLen)
651 ]
647 ]
652 , bgroup "X2"
648 , bgroup "X2"
653− [ benchFold "scan-map" (scanMap 2) (sourceUnfoldrM value)
649+ [ benchFold "scan-map" (scanMap 2) (sourceUnfoldrM streamLen)
654− , benchFold "drop-map" (dropMap 2) (sourceUnfoldrM value)
650+ , benchFold "drop-map" (dropMap 2) (sourceUnfoldrM streamLen)
655− , benchFold "drop-scan" (dropScan 2) (sourceUnfoldrM value)
651+ , benchFold "drop-scan" (dropScan 2) (sourceUnfoldrM streamLen)
656− , benchFold "take-drop" (takeDrop maxValue 2) (sourceUnfoldrM value)
652+ , benchFold "take-drop" (takeDrop streamLen 2) (sourceUnfoldrM streamLen)
657− , benchFold "take-scan" (takeScan maxValue 2) (sourceUnfoldrM value)
653+ , benchFold "take-scan" (takeScan streamLen 2) (sourceUnfoldrM streamLen)
658− , benchFold "take-map" (takeMap maxValue 2) (sourceUnfoldrM value)
654+ , benchFold "take-map" (takeMap streamLen 2) (sourceUnfoldrM streamLen)
659− , benchFold "filter-drop" (filterDrop maxValue 2) (sourceUnfoldrM value)
655+ , benchFold "filter-drop" (filterDrop streamLen 2) (sourceUnfoldrM streamLen)
660− , benchFold "filter-take" (filterTake maxValue 2) (sourceUnfoldrM value)
656+ , benchFold "filter-take" (filterTake streamLen 2) (sourceUnfoldrM streamLen)
661− , benchFold "filter-scan" (filterScan maxValue 2) (sourceUnfoldrM value)
657+ , benchFold "filter-scan" (filterScan streamLen 2) (sourceUnfoldrM streamLen)
662− , benchFold "filter-map" (filterMap maxValue 2) (sourceUnfoldrM value)
658+ , benchFold "filter-map" (filterMap streamLen 2) (sourceUnfoldrM streamLen)
663 ]
659 ]
664 , bgroup "X4"
660 , bgroup "X4"
665− [ benchFold "scan-map" (scanMap 4) (sourceUnfoldrM value)
661+ [ benchFold "scan-map" (scanMap 4) (sourceUnfoldrM streamLen)
666− , benchFold "drop-map" (dropMap 4) (sourceUnfoldrM value)
662+ , benchFold "drop-map" (dropMap 4) (sourceUnfoldrM streamLen)
667− , benchFold "drop-scan" (dropScan 4) (sourceUnfoldrM value)
663+ , benchFold "drop-scan" (dropScan 4) (sourceUnfoldrM streamLen)
668− , benchFold "take-drop" (takeDrop maxValue 4) (sourceUnfoldrM value)
664+ , benchFold "take-drop" (takeDrop streamLen 4) (sourceUnfoldrM streamLen)
669− , benchFold "take-scan" (takeScan maxValue 4) (sourceUnfoldrM value)
665+ , benchFold "take-scan" (takeScan streamLen 4) (sourceUnfoldrM streamLen)
670− , benchFold "take-map" (takeMap maxValue 4) (sourceUnfoldrM value)
666+ , benchFold "take-map" (takeMap streamLen 4) (sourceUnfoldrM streamLen)
671− , benchFold "filter-drop" (filterDrop maxValue 4) (sourceUnfoldrM value)
667+ , benchFold "filter-drop" (filterDrop streamLen 4) (sourceUnfoldrM streamLen)
672− , benchFold "filter-take" (filterTake maxValue 4) (sourceUnfoldrM value)
668+ , benchFold "filter-take" (filterTake streamLen 4) (sourceUnfoldrM streamLen)
673− , benchFold "filter-scan" (filterScan maxValue 4) (sourceUnfoldrM value)
669+ , benchFold "filter-scan" (filterScan streamLen 4) (sourceUnfoldrM streamLen)
674− , benchFold "filter-map" (filterMap maxValue 4) (sourceUnfoldrM value)
670+ , benchFold "filter-map" (filterMap streamLen 4) (sourceUnfoldrM streamLen)
675 ]
671 ]
676 ]
672 ]
677− where
678−
679− maxValue = value
680
673
681o_1_space_list :: Int -> Benchmark
674o_1_space_list :: Int -> Benchmark
682−o_1_space_list value =
675+o_1_space_list streamLen =
683 bgroup "list"
676 bgroup "list"
684 [ bgroup "elimination"
677 [ bgroup "elimination"
685− [ benchList "last" (\xs -> [List.last xs]) (sourceUnfoldrList value)
678+ [ benchList "last" (\xs -> [List.last xs]) (sourceUnfoldrList streamLen)
686 ]
679 ]
687 , bgroup "nested"
680 , bgroup "nested"
688− [ benchList "toNullAp" toNullApNestedList (sourceUnfoldrList value2)
681+ [ benchList "toNullAp" toNullApNestedList (sourceUnfoldrList streamLen2)
689− , benchList "toNull" toNullNestedList (sourceUnfoldrList value2)
682+ , benchList "toNull" toNullNestedList (sourceUnfoldrList streamLen2)
690− , benchList "toNull3" toNullNestedList3 (sourceUnfoldrList value3)
683+ , benchList "toNull3" toNullNestedList3 (sourceUnfoldrList streamLen3)
691− , benchList "filterAllIn" filterAllInNestedList (sourceUnfoldrList value2)
684+ , benchList "filterAllIn" filterAllInNestedList (sourceUnfoldrList streamLen2)
692− , benchList "filterAllOut" filterAllOutNestedList (sourceUnfoldrList value2)
685+ , benchList "filterAllOut" filterAllOutNestedList (sourceUnfoldrList streamLen2)
693 ]
686 ]
694 ]
687 ]
695 where
688 where
696
689
697− value2 = round (P.fromIntegral value**(1/2::P.Double)) -- double nested loop
690+ streamLen2 = round (P.fromIntegral streamLen**(1/2::P.Double)) -- double nested loop
698− value3 = round (P.fromIntegral value**(1/3::P.Double)) -- triple nested loop
691+ streamLen3 = round (P.fromIntegral streamLen**(1/3::P.Double)) -- triple nested loop
699
692
700o_1_space :: Int -> Benchmark
693o_1_space :: Int -> Benchmark
701−o_1_space value =
694+o_1_space streamLen =
702 bgroup (o_1_space_prefix moduleName)
695 bgroup (o_1_space_prefix moduleName)
703− [ o_1_space_generation value
696+ [ o_1_space_generation streamLen
704− , o_1_space_elimination value
697+ , o_1_space_elimination streamLen
705− , o_1_space_nested value
698+ , o_1_space_nested streamLen
706− , o_1_space_transformation value
699+ , o_1_space_transformation streamLen
707− , o_1_space_concat value
700+ , o_1_space_concat streamLen
708− , o_1_space_filtering value
701+ , o_1_space_filtering streamLen
709− , o_1_space_zipping value
702+ , o_1_space_zipping streamLen
710− , o_1_space_mixed value
703+ , o_1_space_mixed streamLen
711− , o_1_space_list value
704+ , o_1_space_list streamLen
712 ]
705 ]
713
706
714o_n_heap :: Int -> Benchmark
707o_n_heap :: Int -> Benchmark
715−o_n_heap value =
708+o_n_heap streamLen =
716 bgroup (o_n_heap_prefix moduleName)
709 bgroup (o_n_heap_prefix moduleName)
717 [ bgroup "transformation"
710 [ bgroup "transformation"
718− [ benchFold "foldlS" (foldlS 1) (sourceUnfoldrM value)
711+ [ benchFold "foldlS" (foldlS 1) (sourceUnfoldrM streamLen)
719 ]
712 ]
720 ]
713 ]
721
714
@@ -724,43 +717,42 @@ benchK :: P.String -> (Int -> Stream P.IO Int) -> Benchmark
724benchK name f = bench name $ nfIO $ randomRIO (1,1) >>= toNull . f
717benchK name f = bench name $ nfIO $ randomRIO (1,1) >>= toNull . f
725
718
726o_n_stack :: Int -> Int -> Int -> Benchmark
719o_n_stack :: Int -> Int -> Int -> Benchmark
727−o_n_stack value iterStreamLen maxIters =
720+o_n_stack streamLen iterStreamLen maxIters =
728 bgroup (o_n_stack_prefix moduleName)
721 bgroup (o_n_stack_prefix moduleName)
729 [ bgroup "elimination"
722 [ bgroup "elimination"
730− [ benchFold "tail" tail (sourceUnfoldrM value)
723+ [ benchFold "tail" tail (sourceUnfoldrM streamLen)
731− , benchFold "nullTail" nullTail (sourceUnfoldrM value)
724+ , benchFold "nullTail" nullTail (sourceUnfoldrM streamLen)
732− , benchFold "headTail" headTail (sourceUnfoldrM value)
725+ , benchFold "headTail" headTail (sourceUnfoldrM streamLen)
733 ]
726 ]
734 , bgroup "transformation"
727 , bgroup "transformation"
735 [
728 [
736 -- XXX why do these need so much stack
729 -- XXX why do these need so much stack
737− benchFold "intersperse" (intersperse maxValue 1) (sourceUnfoldrM value2)
730+ benchFold "intersperse" (intersperse streamLen 1) (sourceUnfoldrM streamLen2)
738− , benchFold "interspersePure" (intersperse maxValue 1) (sourceUnfoldr value2)
731+ , benchFold "interspersePure" (intersperse streamLen 1) (sourceUnfoldr streamLen2)
739 ]
732 ]
740 , bgroup "transformationX4"
733 , bgroup "transformationX4"
741 [
734 [
742− benchFold "intersperse" (intersperse maxValue 4) (sourceUnfoldrM value16)
735+ benchFold "intersperse" (intersperse streamLen 4) (sourceUnfoldrM streamLen16)
743 ]
736 ]
744 , bgroup "iterated"
737 , bgroup "iterated"
745 [ benchK "mapM" (iterateMapM iterStreamLen maxIters)
738 [ benchK "mapM" (iterateMapM iterStreamLen maxIters)
746 , benchK "scan(1/10)" (iterateScan iterStreamLen maxIters)
739 , benchK "scan(1/10)" (iterateScan iterStreamLen maxIters)
747 , benchK "filterEven" (iterateFilterEven iterStreamLen maxIters)
740 , benchK "filterEven" (iterateFilterEven iterStreamLen maxIters)
748− , benchK "takeAll" (iterateTakeAll maxValue iterStreamLen maxIters)
741+ , benchK "takeAll" (iterateTakeAll streamLen iterStreamLen maxIters)
749 , benchK "dropOne" (iterateDropOne iterStreamLen maxIters)
742 , benchK "dropOne" (iterateDropOne iterStreamLen maxIters)
750− , benchK "dropWhileFalse(1/10)" (iterateDropWhileFalse maxValue iterStreamLen maxIters)
743+ , benchK "dropWhileFalse(1/10)" (iterateDropWhileFalse streamLen iterStreamLen maxIters)
751− , benchK "dropWhileTrue" (iterateDropWhileTrue maxValue iterStreamLen maxIters)
744+ , benchK "dropWhileTrue" (iterateDropWhileTrue streamLen iterStreamLen maxIters)
752 ]
745 ]
753 ]
746 ]
754 where
747 where
755− value2 = round (P.fromIntegral value**(1/2::P.Double)) -- double nested loop
748+ streamLen2 = round (P.fromIntegral streamLen**(1/2::P.Double)) -- double nested loop
756− value16 = round (P.fromIntegral value**(1/16::P.Double)) -- triple nested loop
749+ streamLen16 = round (P.fromIntegral streamLen**(1/16::P.Double)) -- triple nested loop
757− maxValue = value
758
750
759o_n_space :: Int -> Benchmark
751o_n_space :: Int -> Benchmark
760−o_n_space value =
752+o_n_space streamLen =
761 bgroup (o_n_space_prefix moduleName)
753 bgroup (o_n_space_prefix moduleName)
762 [ bgroup "elimination"
754 [ bgroup "elimination"
763− [ benchFold "toList" toList (sourceUnfoldrM value)
755+ [ benchFold "toList" toList (sourceUnfoldrM streamLen)
764 ]
756 ]
765 ]
757 ]
766
758
@@ -771,14 +763,14 @@ benchList name run f = bench name $ nfIO $ randomRIO (1,1) >>= return . run . f
771main :: IO ()
763main :: IO ()
772main =
764main =
773 defaultMain
765 defaultMain
774− [ o_1_space value
766+ [ o_1_space streamLen
775− , o_n_stack value iterStreamLen maxIters
767+ , o_n_stack streamLen iterStreamLen maxIters
776− , o_n_heap value
768+ , o_n_heap streamLen
777− , o_n_space value
769+ , o_n_space streamLen
778 ]
770 ]
779
771
780 where
772 where
781
773
782− value = 100000
774+ streamLen = 100000
783 maxIters = 10000
775 maxIters = 10000
784 iterStreamLen = 10
776 iterStreamLen = 10