on master help sign in
split head and tail benchmarks from nullHeadTail
615197dHarendra Kumar
benchmark/BaseStreams.hs+5−2
@@ -45,7 +45,9 @@ main =
45 , bgroup "elimination"
45 , bgroup "elimination"
46 [ benchIO "toNull" D.toNull D.sourceUnfoldrM
46 [ benchIO "toNull" D.toNull D.sourceUnfoldrM
47 , benchIO "uncons" D.uncons D.sourceUnfoldrM
47 , benchIO "uncons" D.uncons D.sourceUnfoldrM
48+ , benchFold "tail" D.tail D.sourceUnfoldrM
49+ , benchIO "nullTail" D.nullTail D.sourceUnfoldrM
48− , benchIO "nullHeadTail" D.nullHeadTail D.sourceUnfoldrM
50+ , benchIO "headTail" D.headTail D.sourceUnfoldrM
49 ]
51 ]
50 , bgroup "transformation"
52 , bgroup "transformation"
51 [ benchIO "scanlM'" D.scan D.sourceUnfoldrM
53 [ benchIO "scanlM'" D.scan D.sourceUnfoldrM
@@ -96,7 +98,8 @@ main =
96 , benchIO "uncons" K.uncons K.sourceUnfoldrM
98 , benchIO "uncons" K.uncons K.sourceUnfoldrM
97 , benchFold "init" K.init K.sourceUnfoldrM
99 , benchFold "init" K.init K.sourceUnfoldrM
98 , benchFold "tail" K.tail K.sourceUnfoldrM
100 , benchFold "tail" K.tail K.sourceUnfoldrM
99− , benchIO "nullHeadTail" K.nullHeadTail K.sourceUnfoldrM
101+ , benchIO "nullTail" K.nullTail K.sourceUnfoldrM
102+ , benchIO "headTail" K.headTail K.sourceUnfoldrM
100 , benchFold "toList" K.toList K.sourceUnfoldrM
103 , benchFold "toList" K.toList K.sourceUnfoldrM
101 , benchFold "fold" K.foldl K.sourceUnfoldrM
104 , benchFold "fold" K.foldl K.sourceUnfoldrM
102 , benchFold "last" K.last K.sourceUnfoldrM
105 , benchFold "last" K.last K.sourceUnfoldrM
benchmark/LinearOps.hs+5−4
@@ -294,10 +294,6 @@ elemIndices n = composeN n $ S.elemIndices maxValue
294{-# INLINE concat #-}
294{-# INLINE concat #-}
295zip, zipM, concat :: Monad m => Stream m Int -> m ()
295zip, zipM, concat :: Monad m => Stream m Int -> m ()
296
296
297−{-# INLINE zipAsync #-}
298−{-# INLINE zipAsyncM #-}
299−zipAsync, zipAsyncM :: S.MonadAsync m => Stream m Int -> m ()
300−
301zip src = do
297zip src = do
302 r <- S.tail src
298 r <- S.tail src
303 let src1 = fromJust r
299 let src1 = fromJust r
@@ -306,6 +302,11 @@ zipM src = do
306 r <- S.tail src
302 r <- S.tail src
307 let src1 = fromJust r
303 let src1 = fromJust r
308 transform (S.zipWithM (curry return) src src1)
304 transform (S.zipWithM (curry return) src src1)
305+
306+{-# INLINE zipAsync #-}
307+{-# INLINE zipAsyncM #-}
308+zipAsync, zipAsyncM :: S.MonadAsync m => Stream m Int -> m ()
309+
309zipAsync src = do
310zipAsync src = do
310 r <- S.tail src
311 r <- S.tail src
311 let src1 = fromJust r
312 let src1 = fromJust r
benchmark/StreamDOps.hs+19−6
@@ -10,6 +10,7 @@
10module StreamDOps where
10module StreamDOps where
11
11
12import Control.Monad (when)
12import Control.Monad (when)
13+import Data.Maybe (isJust)
13import Prelude
14import Prelude
14 (Monad, Int, (+), ($), (.), return, (>), even, (<=),
15 (Monad, Int, (+), ($), (.), return, (>), even, (<=),
15 subtract, undefined, Maybe(..), not, mapM_, (>>=))
16 subtract, undefined, Maybe(..), not, mapM_, (>>=))
@@ -25,7 +26,8 @@ maxValue = value + 1000
25-------------------------------------------------------------------------------
26-------------------------------------------------------------------------------
26
27
27{-# INLINE uncons #-}
28{-# INLINE uncons #-}
28−{-# INLINE nullHeadTail #-}
29+{-# INLINE nullTail #-}
30+{-# INLINE headTail #-}
29{-# INLINE scan #-}
31{-# INLINE scan #-}
30{-# INLINE map #-}
32{-# INLINE map #-}
31{-# INLINE filterEven #-}
33{-# INLINE filterEven #-}
@@ -43,7 +45,7 @@ maxValue = value + 1000
43{-# INLINE composeAllInFilters #-}
45{-# INLINE composeAllInFilters #-}
44{-# INLINE composeAllOutFilters #-}
46{-# INLINE composeAllOutFilters #-}
45{-# INLINE composeMapAllInFilter #-}
47{-# INLINE composeMapAllInFilter #-}
46−uncons, nullHeadTail, map, scan, filterEven, filterAllOut,
48+uncons, nullTail, headTail, map, scan, filterEven, filterAllOut,
47 filterAllIn, takeOne, takeAll, takeWhileTrue, dropAll, dropWhileTrue, zip,
49 filterAllIn, takeOne, takeAll, takeWhileTrue, dropAll, dropWhileTrue, zip,
48 -- concat,
50 -- concat,
49 composeAllInFilters, composeAllOutFilters, composeMapAllInFilter
51 composeAllInFilters, composeAllOutFilters, composeMapAllInFilter
@@ -109,16 +111,27 @@ runStream :: Monad m => Stream m a -> m ()
109runStream = S.runStream
111runStream = S.runStream
110
112
111toNull = runStream
113toNull = runStream
114+
112uncons s = do
115uncons s = do
113 r <- S.uncons s
116 r <- S.uncons s
114 case r of
117 case r of
115 Nothing -> return ()
118 Nothing -> return ()
116 Just (_, t) -> uncons t
119 Just (_, t) -> uncons t
117−nullHeadTail s = do
120+
121+{-# INLINE tail #-}
122+tail :: Monad m => Stream m a -> m ()
123+tail s = S.tail s >>= mapM_ tail
124+
125+nullTail s = do
118 r <- S.null s
126 r <- S.null s
119 when (not r) $ do
127 when (not r) $ do
128+ S.tail s >>= mapM_ nullTail
129+
130+headTail s = do
120− _ <- S.head s
131+ h <- S.head s
132+ when (isJust h) $
121− S.tail s >>= mapM_ nullHeadTail
133+ S.tail s >>= mapM_ headTail
134+
122toList = S.toList
135toList = S.toList
123foldl = S.foldl' (+) 0
136foldl = S.foldl' (+) 0
124last = S.last
137last = S.last
@@ -163,7 +176,7 @@ composeAllInFilters = compose (S.filter (<= maxValue))
163composeAllOutFilters = compose (S.filter (> maxValue))
176composeAllOutFilters = compose (S.filter (> maxValue))
164composeMapAllInFilter = compose (S.filter (<= maxValue) . S.map (subtract 1))
177composeMapAllInFilter = compose (S.filter (<= maxValue) . S.map (subtract 1))
165
178
166−{-# INLINABLE composeScaling #-}
179+{-# INLINE composeScaling #-}
167composeScaling :: Monad m => Int -> Stream m Int -> m ()
180composeScaling :: Monad m => Int -> Stream m Int -> m ()
168composeScaling m =
181composeScaling m =
169 case m of
182 case m of
benchmark/StreamKOps.hs+11−7
@@ -10,6 +10,7 @@
10module StreamKOps where
10module StreamKOps where
11
11
12import Control.Monad (when)
12import Control.Monad (when)
13+import Data.Maybe (isJust)
13import Prelude
14import Prelude
14 (Monad, Int, (+), ($), (.), return, fmap, even, (>), (<=),
15 (Monad, Int, (+), ($), (.), return, fmap, even, (>), (<=),
15 subtract, undefined, Maybe(..), not, mapM_, (>>=))
16 subtract, undefined, Maybe(..), not, mapM_, (>>=))
@@ -28,7 +29,8 @@ maxValue = value + 1000
28
29
29{-# INLINE toNull #-}
30{-# INLINE toNull #-}
30{-# INLINE uncons #-}
31{-# INLINE uncons #-}
31−{-# INLINE nullHeadTail #-}
32+{-# INLINE nullTail #-}
33+{-# INLINE headTail #-}
32{-# INLINE scan #-}
34{-# INLINE scan #-}
33{-# INLINE map #-}
35{-# INLINE map #-}
34{-# INLINE filterEven #-}
36{-# INLINE filterEven #-}
@@ -44,7 +46,7 @@ maxValue = value + 1000
44{-# INLINE composeAllInFilters #-}
46{-# INLINE composeAllInFilters #-}
45{-# INLINE composeAllOutFilters #-}
47{-# INLINE composeAllOutFilters #-}
46{-# INLINE composeMapAllInFilter #-}
48{-# INLINE composeMapAllInFilter #-}
47−toNull, uncons, nullHeadTail, scan, map, filterEven, filterAllOut,
49+toNull, uncons, nullTail, headTail, scan, map, filterEven, filterAllOut,
48 filterAllIn, takeOne, takeAll, takeWhileTrue, dropAll, dropWhileTrue, zip,
50 filterAllIn, takeOne, takeAll, takeWhileTrue, dropAll, dropWhileTrue, zip,
49 concat, composeAllInFilters, composeAllOutFilters,
51 concat, composeAllInFilters, composeAllOutFilters,
50 composeMapAllInFilter
52 composeMapAllInFilter
@@ -141,13 +143,15 @@ init s = do
141tail :: (Monad m, S.IsStream t) => t m a -> m ()
143tail :: (Monad m, S.IsStream t) => t m a -> m ()
142tail s = S.tail s >>= mapM_ tail
144tail s = S.tail s >>= mapM_ tail
143
145
144−-- | If the stream is not null get its head and tail and then do the same to
146+nullTail s = do
145−-- the tail.
146−nullHeadTail s = do
147 r <- S.null s
147 r <- S.null s
148 when (not r) $ do
148 when (not r) $ do
149+ S.tail s >>= mapM_ nullTail
150+
151+headTail s = do
149− _ <- S.head s
152+ h <- S.head s
153+ when (isJust h) $
150− S.tail s >>= mapM_ nullHeadTail
154+ S.tail s >>= mapM_ headTail
151
155
152toList = S.toList
156toList = S.toList
153foldl = S.foldl' (+) 0
157foldl = S.foldl' (+) 0