on master help sign in
Add a middle point for concatMapWith benchmark
22bfa72Harendra Kumar
benchmark/LinearAsync.hs+37−12
@@ -51,7 +51,8 @@ main :: IO ()
51main = do
51main = do
52 -- XXX Fix indentation
52 -- XXX Fix indentation
53 (value, cfg, benches) <- parseCLIOpts defaultStreamSize
53 (value, cfg, benches) <- parseCLIOpts defaultStreamSize
54+ let value2 = round $ sqrt $ (fromIntegral value :: Double)
54− value `seq` runMode (mode cfg) cfg benches
55+ value2 `seq` value `seq` runMode (mode cfg) cfg benches
55 [ bgroup "asyncly"
56 [ bgroup "asyncly"
56 [ benchSrcIO asyncly "unfoldr" (Ops.sourceUnfoldr value)
57 [ benchSrcIO asyncly "unfoldr" (Ops.sourceUnfoldr value)
57 , benchSrcIO asyncly "unfoldrM" (Ops.sourceUnfoldrM value)
58 , benchSrcIO asyncly "unfoldrM" (Ops.sourceUnfoldrM value)
@@ -69,6 +70,8 @@ main = do
69 (maxBuffer 1 . Ops.sourceUnfoldrMN (value `div` 10))
70 (maxBuffer 1 . Ops.sourceUnfoldrMN (value `div` 10))
70 , benchMonadicSrcIO "concatMapWith (2,x/2)"
71 , benchMonadicSrcIO "concatMapWith (2,x/2)"
71 (Ops.concatStreamsWith async 2 (value `div` 2))
72 (Ops.concatStreamsWith async 2 (value `div` 2))
73+ , benchMonadicSrcIO "concatMapWith (sqrt x,sqrt x)"
74+ (Ops.concatStreamsWith async value2 value2)
72 , benchMonadicSrcIO "concatMapWith (x/2,2)"
75 , benchMonadicSrcIO "concatMapWith (x/2,2)"
73 (Ops.concatStreamsWith async (value `div` 2) 2)
76 (Ops.concatStreamsWith async (value `div` 2) 2)
74 ]
77 ]
@@ -83,8 +86,22 @@ main = do
83 , benchIO value "map" $ Ops.map' wAsyncly 1
86 , benchIO value "map" $ Ops.map' wAsyncly 1
84 , benchIO value "fmap" $ Ops.fmap' wAsyncly 1
87 , benchIO value "fmap" $ Ops.fmap' wAsyncly 1
85 , benchIO value "mapM" $ Ops.mapM wAsyncly 1
88 , benchIO value "mapM" $ Ops.mapM wAsyncly 1
89+ , benchSrcIO wAsyncly "unfoldrM maxThreads 1"
90+ (maxThreads 1 . Ops.sourceUnfoldrM value)
91+ , benchSrcIO wAsyncly "unfoldrM maxBuffer 1 (x/10 ops)"
92+ (maxBuffer 1 . Ops.sourceUnfoldrMN (value `div` 10))
93+ -- When we merge streams using wAsync the size of the queue increases
94+ -- slowly because of the binary composition adding just one more item
95+ -- to the work queue only after every scheduling pass through the
96+ -- work queue.
97+ --
98+ -- We should see the memory consumption increasing slowly if these
99+ -- benchmarks are left to run on infinite number of streams of infinite
100+ -- sizes.
86 , benchMonadicSrcIO "concatMapWith (2,x/2)"
101 , benchMonadicSrcIO "concatMapWith (2,x/2)"
87 (Ops.concatStreamsWith wAsync 2 (value `div` 2))
102 (Ops.concatStreamsWith wAsync 2 (value `div` 2))
103+ , benchMonadicSrcIO "concatMapWith (sqrt x,sqrt x)"
104+ (Ops.concatStreamsWith wAsync value2 value2)
88 , benchMonadicSrcIO "concatMapWith (x/2,2)"
105 , benchMonadicSrcIO "concatMapWith (x/2,2)"
89 (Ops.concatStreamsWith wAsync (value `div` 2) 2)
106 (Ops.concatStreamsWith wAsync (value `div` 2) 2)
90 ]
107 ]
@@ -94,7 +111,7 @@ main = do
94 [ benchSrcIO aheadly "unfoldr" (Ops.sourceUnfoldr value)
111 [ benchSrcIO aheadly "unfoldr" (Ops.sourceUnfoldr value)
95 , benchSrcIO aheadly "unfoldrM" (Ops.sourceUnfoldrM value)
112 , benchSrcIO aheadly "unfoldrM" (Ops.sourceUnfoldrM value)
96 , benchSrcIO aheadly "fromFoldableM" (Ops.sourceFromFoldableM value)
113 , benchSrcIO aheadly "fromFoldableM" (Ops.sourceFromFoldableM value)
97− -- , benchSrcIO aheadly "foldMapWith" Ops.sourceFoldMapWith
114+ , benchSrcIO aheadly "foldMapWith" (Ops.sourceFoldMapWith value)
98 , benchSrcIO aheadly "foldMapWithM" (Ops.sourceFoldMapWithM value)
115 , benchSrcIO aheadly "foldMapWithM" (Ops.sourceFoldMapWithM value)
99 , benchSrcIO aheadly "foldMapM" (Ops.sourceFoldMapM value)
116 , benchSrcIO aheadly "foldMapM" (Ops.sourceFoldMapM value)
100 , benchIO value "map" $ Ops.map' aheadly 1
117 , benchIO value "map" $ Ops.map' aheadly 1
@@ -104,35 +121,43 @@ main = do
104 (maxThreads 1 . Ops.sourceUnfoldrM value)
121 (maxThreads 1 . Ops.sourceUnfoldrM value)
105 , benchSrcIO aheadly "unfoldrM maxBuffer 1 (x/10 ops)"
122 , benchSrcIO aheadly "unfoldrM maxBuffer 1 (x/10 ops)"
106 (maxBuffer 1 . Ops.sourceUnfoldrMN (value `div` 10))
123 (maxBuffer 1 . Ops.sourceUnfoldrMN (value `div` 10))
107− -- , benchSrcIO aheadly "fromFoldable" Ops.sourceFromFoldable
124+ , benchSrcIO aheadly "fromFoldable" (Ops.sourceFromFoldable value)
108 , benchMonadicSrcIO "concatMapWith (2,x/2)"
125 , benchMonadicSrcIO "concatMapWith (2,x/2)"
109 (Ops.concatStreamsWith ahead 2 (value `div` 2))
126 (Ops.concatStreamsWith ahead 2 (value `div` 2))
127+ , benchMonadicSrcIO "concatMapWith (sqrt x,sqrt x)"
128+ (Ops.concatStreamsWith ahead value2 value2)
110 , benchMonadicSrcIO "concatMapWith (x/2,2)"
129 , benchMonadicSrcIO "concatMapWith (x/2,2)"
111 (Ops.concatStreamsWith ahead (value `div` 2) 2)
130 (Ops.concatStreamsWith ahead (value `div` 2) 2)
112 ]
131 ]
113 -- XXX need to use smaller streams to finish in reasonable time
132 -- XXX need to use smaller streams to finish in reasonable time
114 , bgroup "parallely"
133 , bgroup "parallely"
134+ [ -- unfoldr is pure and works serially irrespective of the stream type
115− [ benchSrcIO parallely "unfoldr" (Ops.sourceUnfoldr value)
135+ benchSrcIO parallely "unfoldr" (Ops.sourceUnfoldr value)
116 , benchSrcIO parallely "unfoldrM" (Ops.sourceUnfoldrM value)
136 , benchSrcIO parallely "unfoldrM" (Ops.sourceUnfoldrM value)
117− --, benchSrcIO parallely "fromFoldable" Ops.sourceFromFoldable
137+ , benchSrcIO parallely "fromFoldable" (Ops.sourceFromFoldable value)
118 , benchSrcIO parallely "fromFoldableM" (Ops.sourceFromFoldableM value)
138 , benchSrcIO parallely "fromFoldableM" (Ops.sourceFromFoldableM value)
119− -- , benchSrcIO parallely "foldMapWith" Ops.sourceFoldMapWith
139+ , benchSrcIO parallely "foldMapWith" (Ops.sourceFoldMapWith value)
120 , benchSrcIO parallely "foldMapWithM" (Ops.sourceFoldMapWithM value)
140 , benchSrcIO parallely "foldMapWithM" (Ops.sourceFoldMapWithM value)
121 , benchSrcIO parallely "foldMapM" (Ops.sourceFoldMapM value)
141 , benchSrcIO parallely "foldMapM" (Ops.sourceFoldMapM value)
142+ -- map/fmap are pure and therefore no concurrency would be added on top
143+ -- of what the source stream (i.e. unfoldrM) provides.
122 , benchIO value "map" $ Ops.map' parallely 1
144 , benchIO value "map" $ Ops.map' parallely 1
123 , benchIO value "fmap" $ Ops.fmap' parallely 1
145 , benchIO value "fmap" $ Ops.fmap' parallely 1
124 , benchIO value "mapM" $ Ops.mapM parallely 1
146 , benchIO value "mapM" $ Ops.mapM parallely 1
125− -- Zip has only one parallel flavor
147+ , benchMonadicSrcIO "concatMapWith (2,x/2)"
148+ (Ops.concatStreamsWith parallel 2 (value `div` 2))
149+ , benchMonadicSrcIO "concatMapWith (sqrt x,sqrt x)"
150+ (Ops.concatStreamsWith parallel value2 value2)
151+ , benchMonadicSrcIO "concatMapWith (x/2,2)"
152+ (Ops.concatStreamsWith parallel (value `div` 2) 2)
153+ ]
154+ , bgroup "zip"
126− , benchIO value "zip" Ops.zipAsync
155+ [ benchIO value "zip" Ops.zipAsync
127 , benchIO value "zipM" Ops.zipAsyncM
156 , benchIO value "zipM" Ops.zipAsyncM
128 , benchIO value "zipAp" Ops.zipAsyncAp
157 , benchIO value "zipAp" Ops.zipAsyncAp
129 , benchIO value "fmap zipAsyncly" $ Ops.fmap' zipAsyncly 1
158 , benchIO value "fmap zipAsyncly" $ Ops.fmap' zipAsyncly 1
130 -- Parallel stages in a pipeline
159 -- Parallel stages in a pipeline
131 , benchIO value "parAppMap" Ops.parAppMap
160 , benchIO value "parAppMap" Ops.parAppMap
132 , benchIO value "parAppSum" Ops.parAppSum
161 , benchIO value "parAppSum" Ops.parAppSum
133− , benchMonadicSrcIO "concatMapWith (2,x/2)"
134− (Ops.concatStreamsWith parallel 2 (value `div` 2))
135− , benchMonadicSrcIO "concatMapWith (x/10,10)"
136− (Ops.concatStreamsWith parallel (value `div` 10) 10)
137 ]
162 ]
138 ]
163 ]
benchmark/Streamly/Benchmark/Prelude.hs+2−2
@@ -875,8 +875,8 @@ concatStreamsWith
875 -> IO ()
875 -> IO ()
876concatStreamsWith op outer inner n =
876concatStreamsWith op outer inner n =
877 S.drain $ S.concatMapWith op
877 S.drain $ S.concatMapWith op
878− (\_ -> sourceUnfoldrMN inner n)
878+ (\i -> sourceUnfoldrMN (i + inner) i)
879− (sourceUnfoldrMN outer n)
879+ (sourceUnfoldrMN (n + outer) n)
880
880
881{-# INLINE concatMapWithSerial #-}
881{-# INLINE concatMapWithSerial #-}
882concatMapWithSerial :: Int -> Int -> Int -> IO ()
882concatMapWithSerial :: Int -> Int -> Int -> IO ()