on master help sign in
update base stream benchmarks
ec08681Harendra Kumar
benchmark/BaseStreams.hs+20−3
@@ -46,8 +46,8 @@ main = do
46 , benchIO "nullHeadTail" D.nullHeadTail D.sourceUnfoldrM
46 , benchIO "nullHeadTail" D.nullHeadTail D.sourceUnfoldrM
47 ]
47 ]
48 , bgroup "transformation"
48 , bgroup "transformation"
49− [ -- benchIO "scan" D.scan D.sourceUnfoldrM
49+ [ benchIO "scanlM'" D.scan D.sourceUnfoldrM
50− benchIO "map" D.map D.sourceUnfoldrM
50+ , benchIO "map" D.map D.sourceUnfoldrM
51 , benchIO "mapM" D.mapM D.sourceUnfoldrM
51 , benchIO "mapM" D.mapM D.sourceUnfoldrM
52 ]
52 ]
53 , bgroup "filtering"
53 , bgroup "filtering"
@@ -55,6 +55,23 @@ main = do
55 , benchIO "filter-all-out" D.filterAllOut D.sourceUnfoldrM
55 , benchIO "filter-all-out" D.filterAllOut D.sourceUnfoldrM
56 , benchIO "filter-all-in" D.filterAllIn D.sourceUnfoldrM
56 , benchIO "filter-all-in" D.filterAllIn D.sourceUnfoldrM
57 , benchIO "take-all" D.takeAll D.sourceUnfoldrM
57 , benchIO "take-all" D.takeAll D.sourceUnfoldrM
58+ , benchIO "takeWhile-true" D.takeWhileTrue D.sourceUnfoldrM
59+ , benchIO "drop-all" D.dropAll D.sourceUnfoldrM
60+ , benchIO "dropWhile-true" D.dropWhileTrue D.sourceUnfoldrM
61+ ]
62+ , benchIO "zip" D.zip D.sourceUnfoldrM
63+ , bgroup "compose"
64+ [ benchIO "mapM" D.composeMapM D.sourceUnfoldrM
65+ , benchIO "map-with-all-in-filter" D.composeMapAllInFilter D.sourceUnfoldrM
66+ , benchIO "all-in-filters" D.composeAllInFilters D.sourceUnfoldrM
67+ , benchIO "all-out-filters" D.composeAllOutFilters D.sourceUnfoldrM
68+ ]
69+ -- Scaling with same operation in sequence
70+ , bgroup "compose-scaling"
71+ [ benchIO "1" (D.composeScaling 1) D.sourceUnfoldrM
72+ , benchIO "2" (D.composeScaling 2) D.sourceUnfoldrM
73+ , benchIO "3" (D.composeScaling 3) D.sourceUnfoldrM
74+ , benchIO "4" (D.composeScaling 4) D.sourceUnfoldrM
58 ]
75 ]
59 ]
76 ]
60 , bgroup "streamK"
77 , bgroup "streamK"
@@ -82,7 +99,7 @@ main = do
82 [ benchIO "scan" K.scan K.sourceUnfoldrM
99 [ benchIO "scan" K.scan K.sourceUnfoldrM
83 , benchIO "map" K.map K.sourceUnfoldrM
100 , benchIO "map" K.map K.sourceUnfoldrM
84 , benchIO "mapM" K.mapM K.sourceUnfoldrM
101 , benchIO "mapM" K.mapM K.sourceUnfoldrM
85− , benchIO "concat" K.concat K.sourceUnfoldrM
102+ -- , benchIO "concat" K.concat K.sourceUnfoldrM
86 ]
103 ]
87 , bgroup "filtering"
104 , bgroup "filtering"
88 [ benchIO "filter-even" K.filterEven K.sourceUnfoldrM
105 [ benchIO "filter-even" K.filterEven K.sourceUnfoldrM
benchmark/StreamDOps.hs+14−21
@@ -9,17 +9,14 @@
9
9
10module StreamDOps where
10module StreamDOps where
11
11
12−-- import Prelude
13− -- (Monad, Int, (+), ($), (.), return, fmap, even, (>), (<=),
14− -- subtract, undefined, Maybe(..))
15import Prelude
12import Prelude
16− (Monad, Int, (+), (.), return, (>), even, (<=),
13+ (Monad, Int, (+), ($), (.), return, (>), even, (<=),
17− Maybe(..), not)
14+ subtract, undefined, Maybe(..), not)
18
15
19import qualified Streamly.Streams.StreamD as S
16import qualified Streamly.Streams.StreamD as S
20
17
21value, maxValue :: Int
18value, maxValue :: Int
22−value = 1000000
19+value = 100000
23maxValue = value + 1000
20maxValue = value + 1000
24
21
25-------------------------------------------------------------------------------
22-------------------------------------------------------------------------------
@@ -28,34 +25,32 @@ maxValue = value + 1000
28
25
29{-# INLINE uncons #-}
26{-# INLINE uncons #-}
30{-# INLINE nullHeadTail #-}
27{-# INLINE nullHeadTail #-}
31−-- {-# INLINE scan #-}
28+{-# INLINE scan #-}
32{-# INLINE map #-}
29{-# INLINE map #-}
33{-# INLINE filterEven #-}
30{-# INLINE filterEven #-}
34{-# INLINE filterAllOut #-}
31{-# INLINE filterAllOut #-}
35{-# INLINE filterAllIn #-}
32{-# INLINE filterAllIn #-}
36{-# INLINE takeOne #-}
33{-# INLINE takeOne #-}
37{-# INLINE takeAll #-}
34{-# INLINE takeAll #-}
38−{-
39{-# INLINE takeWhileTrue #-}
35{-# INLINE takeWhileTrue #-}
40{-# INLINE dropAll #-}
36{-# INLINE dropAll #-}
41{-# INLINE dropWhileTrue #-}
37{-# INLINE dropWhileTrue #-}
42{-# INLINE zip #-}
38{-# INLINE zip #-}
39+{-
43{-# INLINE concat #-}
40{-# INLINE concat #-}
41+-}
44{-# INLINE composeAllInFilters #-}
42{-# INLINE composeAllInFilters #-}
45{-# INLINE composeAllOutFilters #-}
43{-# INLINE composeAllOutFilters #-}
46{-# INLINE composeMapAllInFilter #-}
44{-# INLINE composeMapAllInFilter #-}
47−-}
48−uncons, nullHeadTail, map, filterEven, filterAllOut,
45+uncons, nullHeadTail, map, scan, filterEven, filterAllOut,
49− filterAllIn, takeOne, takeAll -- takeWhileTrue, dropAll, dropWhileTrue, zip,
46+ filterAllIn, takeOne, takeAll, takeWhileTrue, dropAll, dropWhileTrue, zip,
47+ -- concat,
50− -- concat, composeAllInFilters, composeAllOutFilters,
48+ composeAllInFilters, composeAllOutFilters, composeMapAllInFilter
51− -- composeMapAllInFilter
52 :: Monad m
49 :: Monad m
53 => Stream m Int -> m ()
50 => Stream m Int -> m ()
54
51
55−{-
56{-# INLINE composeMapM #-}
52{-# INLINE composeMapM #-}
57−composeMapM :: S.MonadAsync m => Stream m Int -> m ()
53+composeMapM :: Monad m => Stream m Int -> m ()
58−-}
59
54
60{-# INLINE toList #-}
55{-# INLINE toList #-}
61toList :: Monad m => Stream m Int -> m [Int]
56toList :: Monad m => Stream m Int -> m [Int]
@@ -140,7 +135,7 @@ last = S.last
140transform :: Monad m => Stream m a -> m ()
135transform :: Monad m => Stream m a -> m ()
141transform = runStream
136transform = runStream
142
137
143−-- scan = transform . S.scanl' (+) 0
138+scan = transform . S.scanlM' (\a b -> return (a + b)) 0
144map = transform . S.map (+1)
139map = transform . S.map (+1)
145mapM = transform . S.mapM return
140mapM = transform . S.mapM return
146filterEven = transform . S.filter even
141filterEven = transform . S.filter even
@@ -148,7 +143,6 @@ filterAllOut = transform . S.filter (> maxValue)
148filterAllIn = transform . S.filter (<= maxValue)
143filterAllIn = transform . S.filter (<= maxValue)
149takeOne = transform . S.take 1
144takeOne = transform . S.take 1
150takeAll = transform . S.take maxValue
145takeAll = transform . S.take maxValue
151−{-
152takeWhileTrue = transform . S.takeWhile (<= maxValue)
146takeWhileTrue = transform . S.takeWhile (<= maxValue)
153dropAll = transform . S.drop maxValue
147dropAll = transform . S.drop maxValue
154dropWhileTrue = transform . S.dropWhile (<= maxValue)
148dropWhileTrue = transform . S.dropWhile (<= maxValue)
@@ -158,7 +152,7 @@ dropWhileTrue = transform . S.dropWhile (<= maxValue)
158-------------------------------------------------------------------------------
152-------------------------------------------------------------------------------
159
153
160zip src = transform $ (S.zipWith (,) src src)
154zip src = transform $ (S.zipWith (,) src src)
161−concat _n = return ()
155+-- concat _n = return ()
162
156
163-------------------------------------------------------------------------------
157-------------------------------------------------------------------------------
164-- Composition
158-- Composition
@@ -171,7 +165,7 @@ compose f = transform . f . f . f . f
171composeMapM = compose (S.mapM return)
165composeMapM = compose (S.mapM return)
172composeAllInFilters = compose (S.filter (<= maxValue))
166composeAllInFilters = compose (S.filter (<= maxValue))
173composeAllOutFilters = compose (S.filter (> maxValue))
167composeAllOutFilters = compose (S.filter (> maxValue))
174−composeMapAllInFilter = compose (S.filter (<= maxValue) . fmap (subtract 1))
168+composeMapAllInFilter = compose (S.filter (<= maxValue) . S.map (subtract 1))
175
169
176{-# INLINABLE composeScaling #-}
170{-# INLINABLE composeScaling #-}
177composeScaling :: Monad m => Int -> Stream m Int -> m ()
171composeScaling :: Monad m => Int -> Stream m Int -> m ()
@@ -183,4 +177,3 @@ composeScaling m =
183 4 -> transform . f . f . f . f
177 4 -> transform . f . f . f . f
184 _ -> undefined
178 _ -> undefined
185 where f = S.filter (<= maxValue)
179 where f = S.filter (<= maxValue)
186− -}
benchmark/StreamKOps.hs+1−1
@@ -18,7 +18,7 @@ import qualified Streamly.Streams.Prelude as S
18import qualified Streamly.SVar as S
18import qualified Streamly.SVar as S
19
19
20value, maxValue :: Int
20value, maxValue :: Int
21−value = 1000000
21+value = 100000
22maxValue = value + 1000
22maxValue = value + 1000
23
23
24-------------------------------------------------------------------------------
24-------------------------------------------------------------------------------