@@ -88,18 +88,54 @@ inspect $ 'roundRobin2 `hasNoType` ''SPEC
88inspect $ 'roundRobin2 `hasNoType` ''D.InterleaveState
88inspect $ 'roundRobin2 `hasNoType` ''D.InterleaveState
91−o_1_space_joining :: Int -> [Benchmark]
91+{-# INLINE sourceUnfoldrMUF #-}
92−o_1_space_joining value =
92+-- (count, value)
93− [ bgroup "joining"
93+sourceUnfoldrMUF :: Monad m => Int -> UF.Unfold m (Int, Int) Int
94− [ benchIOSrc1 "wSerial (2,x/2)" (wSerial2 value)
94+sourceUnfoldrMUF count = UF.unfoldrM step
95− , benchIOSrc1 "interleave (2,x/2)" (interleave2 value)
95+ where
96− , benchIOSrc1 "roundRobin (2,x/2)" (roundRobin2 value)
96+ step (cnt, start) =
98− ]
98+ if cnt > start + count
100+ else Just (cnt, (cnt + 1, start))
102+{-# INLINE unfoldManyInterleave #-}
103+unfoldManyInterleave :: Int -> Int -> Int -> IO ()
104+unfoldManyInterleave outer inner n =
105+ S.drain $ Internal.unfoldManyInterleave
106+ -- (UF.lmap return (UF.replicateM inner))
107+ (UF.lmap (\x -> (x,x)) (sourceUnfoldrMUF inner))
108+ (sourceUnfoldrM outer n)
100−-------------------------------------------------------------------------------
110+#ifdef INSPECTION
101−-- Concat
111+inspect $ hasNoTypeClasses 'unfoldManyInterleave
102−-------------------------------------------------------------------------------
112+-- inspect $ 'unfoldManyInterleave `hasNoType` ''SPEC
113+-- inspect $ 'unfoldManyInterleave `hasNoType`
114+-- ''D.ConcatUnfoldInterleaveState
117+{-# INLINE unfoldManyRoundRobin #-}
118+unfoldManyRoundRobin :: Int -> Int -> Int -> IO ()
119+unfoldManyRoundRobin outer inner n =
120+ S.drain $ Internal.unfoldManyRoundRobin
121+ -- (UF.lmap return (UF.replicateM inner))
122+ (UF.lmap (\x -> (x,x)) (sourceUnfoldrMUF inner))
123+ (sourceUnfoldrM outer n)
126+inspect $ hasNoTypeClasses 'unfoldManyRoundRobin
127+-- inspect $ 'unfoldManyRoundRobin `hasNoType` ''SPEC
128+-- inspect $ 'unfoldManyRoundRobin `hasNoType`
129+-- ''D.ConcatUnfoldInterleaveState
132+{-# INLINE concatPairsWithWSerial #-}
133+concatPairsWithWSerial :: Int -> Int -> Int -> IO ()
134+concatPairsWithWSerial = concatPairsWith Internal.wSerial
136+{-# INLINE concatPairsWithRoundrobin #-}
137+concatPairsWithRoundrobin :: Int -> Int -> Int -> IO ()
138+concatPairsWithRoundrobin = concatPairsWith Internal.roundrobin
104{-# INLINE concatMapWithWSerial #-}
140{-# INLINE concatMapWithWSerial #-}
105concatMapWithWSerial :: Int -> Int -> Int -> IO ()
141concatMapWithWSerial :: Int -> Int -> Int -> IO ()
@@ -110,86 +146,189 @@ inspect $ hasNoTypeClasses 'concatMapWithWSerial
110inspect $ 'concatMapWithWSerial `hasNoType` ''SPEC
146inspect $ 'concatMapWithWSerial `hasNoType` ''SPEC
149+o_1_space_joining :: Int -> [Benchmark]
150+o_1_space_joining value =
151+ [ bgroup "joining (2 of n/2)"
152+ [ benchIOSrc1 "wSerial" (wSerial2 value)
153+ , benchIOSrc1 "interleave" (interleave2 value)
154+ , benchIOSrc1 "roundRobin" (roundRobin2 value)
156+ "concatMapWithWSerial"
157+ (concatMapWithWSerial 2 (value `div` 2))
159+ "concatMapWithInterleave"
160+ (concatStreamsWith Internal.interleave 2 (value `div` 2))
162+ "concatMapWithRoundrobin"
163+ (concatStreamsWith Internal.roundrobin 2 (value `div` 2))
165+ "unfoldManyInterleave"
166+ (unfoldManyInterleave 2 (value `div` 2))
168+ "concatPairsWithWSerial"
169+ (concatPairsWithWSerial 2 (value `div` 2))
171+ "concatPairsWithRoundrobin"
172+ (concatPairsWithRoundrobin 2 (value `div` 2))
176+-------------------------------------------------------------------------------
178+-------------------------------------------------------------------------------
113o_1_space_concat :: Int -> [Benchmark]
180o_1_space_concat :: Int -> [Benchmark]
114o_1_space_concat value =
181o_1_space_concat value =
115− [ bgroup "concat"
182+ [ bgroup "concatMapWith"
116 [ benchIOSrc1
183 [ benchIOSrc1
117− "concatMapWithWSerial (2,x/2)"
184+ "concatMapWithWSerial (n of 1)"
118− (concatMapWithWSerial 2 (value `div` 2))
185+ (concatStreamsWith wSerial value 1)
187+ "concatMapWithWSerial (sqrtVal of sqrtVal)"
188+ (concatStreamsWith wSerial sqrtVal sqrtVal)
189+ -- concatMapWith using StreamD versions of interleave operations are
190+ -- all quadratic, we just measure the sqrtVal benchmark for comparison.
119 , benchIOSrc1
192 , benchIOSrc1
120− "concatMapWithWSerial (x/2,2)"
193+ "concatMapWithInterleave (n of 1)"
121− (concatMapWithWSerial (value `div` 2) 2)
194+ (concatStreamsWith Internal.interleave value 1)
197+ "concatMapWithInterleave (sqrtVal of sqrtVal)"
198+ (concatStreamsWith Internal.interleave sqrtVal sqrtVal)
200+ "concatMapWithRoundrobin (sqrtVal of sqrtVal)"
201+ (concatStreamsWith Internal.roundrobin sqrtVal sqrtVal)
125−{-# INLINE unfoldManyInterleaveRepl4xN #-}
205+ where
126−unfoldManyInterleaveRepl4xN :: Int -> Int -> IO ()
127−unfoldManyInterleaveRepl4xN value n =
128− S.drain $ Internal.unfoldManyInterleave
129− (UF.lmap return (UF.replicateM 4))
130− (sourceUnfoldrM (value `div` 4) n)
132−#ifdef INSPECTION
207+ sqrtVal = round $ sqrt (fromIntegral value :: Double)
133−inspect $ hasNoTypeClasses 'unfoldManyInterleaveRepl4xN
134−-- inspect $ 'unfoldManyInterleaveRepl4xN `hasNoType` ''SPEC
135−-- inspect $ 'unfoldManyInterleaveRepl4xN `hasNoType`
136−-- ''D.ConcatUnfoldInterleaveState
139−{-# INLINE unfoldManyRoundRobinRepl4xN #-}
209+{-# INLINE concatPairsWithInterleave #-}
140−unfoldManyRoundRobinRepl4xN :: Int -> Int -> IO ()
210+concatPairsWithInterleave :: Int -> Int -> Int -> IO ()
141−unfoldManyRoundRobinRepl4xN value n =
211+concatPairsWithInterleave = concatPairsWith Internal.interleave
142− S.drain $ Internal.unfoldManyRoundRobin
143− (UF.lmap return (UF.replicateM 4))
144− (sourceUnfoldrM (value `div` 4) n)
146−#ifdef INSPECTION
213+{-# INLINE concatPairsWithInterleaveSuffix #-}
147−inspect $ hasNoTypeClasses 'unfoldManyRoundRobinRepl4xN
214+concatPairsWithInterleaveSuffix :: Int -> Int -> Int -> IO ()
148−-- inspect $ 'unfoldManyRoundRobinRepl4xN `hasNoType` ''SPEC
215+concatPairsWithInterleaveSuffix = concatPairsWith Internal.interleaveSuffix
149−-- inspect $ 'unfoldManyRoundRobinRepl4xN `hasNoType`
216+
150−-- ''D.ConcatUnfoldInterleaveState
217+{-# INLINE concatPairsWithInterleaveInfix #-}
151−#endif
218+concatPairsWithInterleaveInfix :: Int -> Int -> Int -> IO ()
219+concatPairsWithInterleaveInfix = concatPairsWith Internal.interleaveInfix
221+{-# INLINE concatPairsWithInterleaveMin #-}
222+concatPairsWithInterleaveMin :: Int -> Int -> Int -> IO ()
223+concatPairsWithInterleaveMin = concatPairsWith Internal.interleaveMin
153o_n_heap_concat :: Int -> [Benchmark]
225o_n_heap_concat :: Int -> [Benchmark]
154o_n_heap_concat value =
226o_n_heap_concat value =
155− [ bgroup "concat"
227+ [ bgroup "concatPairsWith"
157− -- interleave x/4 streams of 4 elements each. Needs to buffer
158− -- proportional to x/4. This is different from WSerial because
159− -- WSerial expands slowly because of binary interleave behavior and
160− -- this expands immediately because of Nary interleave behavior.
161 benchIOSrc1
229 benchIOSrc1
162− "unfoldManyInterleaveRepl (x/4,4)"
230+ "unfoldManyInterleave (n of 1)"
163− (unfoldManyInterleaveRepl4xN value)
231+ (unfoldManyInterleave value 1)
233+ "unfoldManyInterleave (sqrtVal of sqrtVal)"
234+ (unfoldManyInterleave sqrtVal sqrtVal)
237+ "unfoldManyRoundRobin (n of 1)"
238+ (unfoldManyRoundRobin value 1)
240+ "unfoldManyRoundRobin (sqrtVal of sqrtVal)"
241+ (unfoldManyRoundRobin sqrtVal sqrtVal)
244+ "concatPairsWithWSerial (n of 1)"
245+ (concatPairsWithWSerial value 1)
164 , benchIOSrc1
246 , benchIOSrc1
165− "unfoldManyRoundRobinRepl (x/4,4)"
247+ "concatPairsWithWSerial (sqrtVal of sqrtVal)"
166− (unfoldManyRoundRobinRepl4xN value)
248+ (concatPairsWithWSerial sqrtVal sqrtVal)
251+ "concatPairsWithInterleave (n of 1)"
252+ (concatPairsWithInterleave value 1)
254+ "concatPairsWithInterleave (sqrtVal of sqrtVal)"
255+ (concatPairsWithInterleave sqrtVal sqrtVal)
258+ "concatPairsWithInterleaveSuffix (n of 1)"
259+ (concatPairsWithInterleaveSuffix value 1)
261+ "concatPairsWithInterleaveSuffix (sqrtVal of sqrtVal)"
262+ (concatPairsWithInterleaveSuffix sqrtVal sqrtVal)
265+ "concatPairsWithInterleaveInfix (n of 1)"
266+ (concatPairsWithInterleaveInfix value 1)
268+ "concatPairsWithInterleaveInfix (sqrtVal of sqrtVal)"
269+ (concatPairsWithInterleaveInfix sqrtVal sqrtVal)
272+ "concatPairsWithInterleaveMin (n of 1)"
273+ (concatPairsWithInterleaveMin value 1)
275+ "concatPairsWithInterleaveMin (sqrtVal of sqrtVal)"
276+ (concatPairsWithInterleaveMin sqrtVal sqrtVal)
279+ "concatPairsWithRoundrobin (n of 1)"
280+ (concatPairsWithRoundrobin value 1)
282+ "concatPairsWithRoundrobin (sqrtVal of sqrtVal)"
283+ (concatPairsWithRoundrobin sqrtVal sqrtVal)
289+ sqrtVal = round $ sqrt (fromIntegral value :: Double)
170-------------------------------------------------------------------------------
291-------------------------------------------------------------------------------
172-------------------------------------------------------------------------------
293-------------------------------------------------------------------------------
174o_1_space_outerProduct :: Int -> [Benchmark]
295o_1_space_outerProduct :: Int -> [Benchmark]
175o_1_space_outerProduct value =
296o_1_space_outerProduct value =
176− [ bgroup "monad-outer-product"
297+ [ bgroup "outer-product"
299+ "drain applicative (+) (sqrtVal of sqrtVal)"
177− [ benchIO "toNullAp" $ toNullAp value fromWSerial
300+ (toNullAp value fromWSerial)
302+ "drain monad (+) (sqrtVal of sqrtVal)"
178− , benchIO "toNullM" $ toNullM value fromWSerial
303+ (toNullM value fromWSerial)
305+ "drain monad (+) (cbrtVal of cbrtVal of cbrtVal)"
179− , benchIO "toNullM3" $ toNullM3 value fromWSerial
306+ (toNullM3 value fromWSerial)
308+ "filterAllOut monad (+) (sqrtVal of sqrtVal)"
180− , benchIO "filterAllOutM" $ filterAllOutM value fromWSerial
309+ (filterAllOutM value fromWSerial)
311+ "filterAllIn monad (+) (sqrtVal of sqrtVal)"
181− , benchIO "filterAllInM" $ filterAllInM value fromWSerial
312+ (filterAllInM value fromWSerial)
314+ "filterSome monad (+) (sqrtVal of sqrtVal)"
182− , benchIO "filterSome" $ filterSome value fromWSerial
315+ (filterSome value fromWSerial)
317+ "breakAfterSome monad (+) (sqrtVal of sqrtVal)"
183− , benchIO "breakAfterSome" $ breakAfterSome value fromWSerial
318+ (breakAfterSome value fromWSerial)
187o_n_space_outerProduct :: Int -> [Benchmark]
322o_n_space_outerProduct :: Int -> [Benchmark]
188o_n_space_outerProduct value =
323o_n_space_outerProduct value =
190− "monad-outer-product"
325+ "outer-product"
327+ "toList monad (+) (sqrtVal of sqrtVal)"
191− [ benchIO "toList" $ toListM value fromWSerial
328+ (toListM value fromWSerial)
330+ "toListSome monad (+) (sqrtVal of sqrtVal)"
192− , benchIO "toListSome" $ toListSome value fromWSerial
331+ (toListSome value fromWSerial)