@@ -1216,7 +1216,7 @@ iterateSource ::
12161216 -> Int
12171217 -> Int
12181218 -> SerialT m Int
1219−iterateSource g i n = f i (sourceUnfoldrMN iterStreamLen n)
1219+iterateSource g i n = f i (sourceUnfoldrM iterStreamLen n)
12201220 where
12211221 f (0 :: Int) m = g m
12221222 f x m = g (f (x P.- 1) m)
@@ -1324,23 +1324,23 @@ o_1_space_pipesX4 value =
13241324serial2 :: Int -> Int -> IO ()
13251325serial2 count n =
13261326 S.drain $
1327− S.serial (sourceUnfoldrMN count n) (sourceUnfoldrMN count (n + 1))
1327+ S.serial (sourceUnfoldrM count n) (sourceUnfoldrM count (n + 1))
13281328
13291329{-# INLINE serial4 #-}
13301330serial4 :: Int -> Int -> IO ()
13311331serial4 count n =
13321332 S.drain $
13331333 S.serial
1334− (S.serial (sourceUnfoldrMN count n) (sourceUnfoldrMN count (n + 1)))
1334+ (S.serial (sourceUnfoldrM count n) (sourceUnfoldrM count (n + 1)))
13351335 (S.serial
1336− (sourceUnfoldrMN count (n + 2))
1337− (sourceUnfoldrMN count (n + 3)))
1336+ (sourceUnfoldrM count (n + 2))
1337+ (sourceUnfoldrM count (n + 3)))
13381338
13391339{-# INLINE append2 #-}
13401340append2 :: Int -> Int -> IO ()
13411341append2 count n =
13421342 S.drain $
1343− Internal.append (sourceUnfoldrMN count n) (sourceUnfoldrMN count (n + 1))
1343+ Internal.append (sourceUnfoldrM count n) (sourceUnfoldrM count (n + 1))
13441344
13451345{-# INLINE append4 #-}
13461346append4 :: Int -> Int -> IO ()
@@ -1348,11 +1348,11 @@ append4 count n =
13481348 S.drain $
13491349 Internal.append
13501350 (Internal.append
1351− (sourceUnfoldrMN count n)
1352− (sourceUnfoldrMN count (n + 1)))
1351+ (sourceUnfoldrM count n)
1352+ (sourceUnfoldrM count (n + 1)))
13531353 (Internal.append
1354− (sourceUnfoldrMN count (n + 2))
1355− (sourceUnfoldrMN count (n + 3)))
1354+ (sourceUnfoldrM count (n + 2))
1355+ (sourceUnfoldrM count (n + 3)))
13561356
13571357#ifdef INSPECTION
13581358inspect $ hasNoTypeClasses 'append2
@@ -1370,8 +1370,8 @@ mergeBy count n =
13701370 S.drain $
13711371 S.mergeBy
13721372 P.compare
1373− (sourceUnfoldrMN count n)
1374− (sourceUnfoldrMN count (n + 1))
1373+ (sourceUnfoldrM count n)
1374+ (sourceUnfoldrM count (n + 1))
13751375
13761376#ifdef INSPECTION
13771377inspect $ hasNoTypeClasses 'mergeBy
@@ -1397,10 +1397,13 @@ o_1_space_joining value =
13971397o_1_space_concatFoldable :: Int -> [Benchmark]
13981398o_1_space_concatFoldable value =
13991399 [ bgroup "concat-foldable"
1400− [ benchIOSrc serially "foldMapWith" (sourceFoldMapWith value)
1401− , benchIOSrc serially "foldMapWithM" (sourceFoldMapWithM value)
1402− , benchIOSrc serially "foldMapM" (sourceFoldMapM value)
1403− , benchIOSrc serially "foldWithConcatMapId" (sourceConcatMapId value)
1400+ [ benchIOSrc serially "foldMapWith (<>) (List)"
1401+ (sourceFoldMapWith value)
1402+ , benchIOSrc serially "foldMapWith (<>) (Stream)"
1403+ (sourceFoldMapWithStream value)
1404+ , benchIOSrc serially "foldMapWithM (<>) (List)"
1405+ (sourceFoldMapWithM value)
1406+ , benchIOSrc serially "foldMapM (List)" (sourceFoldMapM value)
14041407 ]
14051408 ]
14061409
@@ -1414,8 +1417,8 @@ o_1_space_concatFoldable value =
14141417concatMap :: Int -> Int -> Int -> IO ()
14151418concatMap outer inner n =
14161419 S.drain $ S.concatMap
1417− (\_ -> sourceUnfoldrMN inner n)
1418− (sourceUnfoldrMN outer n)
1420+ (\_ -> sourceUnfoldrM inner n)
1421+ (sourceUnfoldrM outer n)
14191422
14201423#ifdef INSPECTION
14211424inspect $ hasNoTypeClasses 'concatMap
@@ -1428,8 +1431,8 @@ inspect $ 'concatMap `hasNoType` ''SPEC
14281431concatMapPure :: Int -> Int -> Int -> IO ()
14291432concatMapPure outer inner n =
14301433 S.drain $ S.concatMap
1431− (\_ -> sourceUnfoldrN inner n)
1432− (sourceUnfoldrN outer n)
1434+ (\_ -> sourceUnfoldr inner n)
1435+ (sourceUnfoldr outer n)
14331436
14341437#ifdef INSPECTION
14351438inspect $ hasNoTypeClasses 'concatMapPure
@@ -1438,14 +1441,14 @@ inspect $ 'concatMapPure `hasNoType` ''SPEC
14381441
14391442-- concatMap replicate/unfoldrM
14401443
1441−{-# INLINE concatMapRepl4xN #-}
1442−concatMapRepl4xN :: Int -> Int -> IO ()
1443−concatMapRepl4xN value n = S.drain $ S.concatMap (S.replicate 4)
1444− (sourceUnfoldrMN (value `div` 4) n)
1444+{-# INLINE concatMapRepl #-}
1445+concatMapRepl :: Int -> Int -> Int -> IO ()
1446+concatMapRepl outer inner n =
1447+ S.drain $ S.concatMap (S.replicate inner) (sourceUnfoldrM outer n)
14451448
14461449#ifdef INSPECTION
1447−inspect $ hasNoTypeClasses 'concatMapRepl4xN
1448−inspect $ 'concatMapRepl4xN `hasNoType` ''SPEC
1450+inspect $ hasNoTypeClasses 'concatMapRepl
1451+inspect $ 'concatMapRepl `hasNoType` ''SPEC
14491452#endif
14501453
14511454-- concatMapWith
@@ -1472,41 +1475,65 @@ inspect $ 'concatMapWithAppend `hasNoType` ''SPEC
14721475
14731476-- concatUnfold replicate/unfoldrM
14741477
1475−{-# INLINE concatUnfoldRepl4xN #-}
1476−concatUnfoldRepl4xN :: Int -> Int -> IO ()
1477−concatUnfoldRepl4xN value n =
1478− S.drain $ S.concatUnfold
1479− (UF.replicateM 4)
1480− (sourceUnfoldrMN (value `div` 4) n)
1478+{-# INLINE concatUnfoldRepl #-}
1479+concatUnfoldRepl :: Int -> Int -> Int -> IO ()
1480+concatUnfoldRepl outer inner n =
1481+ S.drain $ S.concatUnfold (UF.replicateM inner) (sourceUnfoldrM outer n)
14811482
14821483#ifdef INSPECTION
1483−inspect $ hasNoTypeClasses 'concatUnfoldRepl4xN
1484−inspect $ 'concatUnfoldRepl4xN `hasNoType` ''D.ConcatMapUState
1485−inspect $ 'concatUnfoldRepl4xN `hasNoType` ''SPEC
1484+inspect $ hasNoTypeClasses 'concatUnfoldRepl
1485+inspect $ 'concatUnfoldRepl `hasNoType` ''D.ConcatMapUState
1486+inspect $ 'concatUnfoldRepl `hasNoType` ''SPEC
14861487#endif
14871488
14881489o_1_space_concat :: Int -> [Benchmark]
1489−o_1_space_concat value =
1490+o_1_space_concat value = sqrtVal `seq`
14901491 [ bgroup "concat"
1491− [ benchIOSrc1 "concatMapPure (2,x/2)"
1492− (concatMapPure 2 (value `div` 2))
1493− , benchIOSrc1 "concatMap (2,x/2)"
1494− (concatMap 2 (value `div` 2))
1495− , benchIOSrc1 "concatMap (x/2,2)"
1496− (concatMap (value `div` 2) 2)
1497− , benchIOSrc1 "concatMapRepl (x/4,4)"
1498− (concatMapRepl4xN value)
1499− , benchIOSrc1 "concatUnfoldRepl (x/4,4)"
1500− (concatUnfoldRepl4xN value)
1501− , benchIOSrc1 "concatMapWithSerial (2,x/2)"
1502− (concatMapWithSerial 2 (value `div` 2))
1503− , benchIOSrc1 "concatMapWithSerial (x/2,2)"
1504− (concatMapWithSerial (value `div` 2) 2)
1505− , benchIOSrc1 "concatMapWithAppend (2,x/2)"
1492+ [ benchIOSrc1 "concatMapPure (n of 1)"
1493+ (concatMapPure value 1)
1494+ , benchIOSrc1 "concatMapPure (sqrt n of sqrt n)"
1495+ (concatMapPure sqrtVal sqrtVal)
1496+ , benchIOSrc1 "concatMapPure (1 of n)"
1497+ (concatMapPure 1 value)
1498+
1499+ -- This is for comparison with foldMapWith
1500+ , benchIOSrc serially "concatMapId (n of 1) (fromFoldable)"
1501+ (S.concatMap id . sourceConcatMapId value)
1502+
1503+ , benchIOSrc1 "concatMap (n of 1)"
1504+ (concatMap value 1)
1505+ , benchIOSrc1 "concatMap (sqrt n of sqrt n)"
1506+ (concatMap sqrtVal sqrtVal)
1507+ , benchIOSrc1 "concatMap (1 of n)"
1508+ (concatMap 1 value)
1509+
1510+ -- This is for comparison with foldMapWith
1511+ , benchIOSrc serially "concatMapWithId (n of 1) (fromFoldable)"
1512+ (S.concatMapWith serial id . sourceConcatMapId value)
1513+
1514+ , benchIOSrc1 "concatMapWith (n of 1)"
1515+ (concatMapWithSerial value 1)
1516+ , benchIOSrc1 "concatMapWith (sqrt n of sqrt n)"
1517+ (concatMapWithSerial sqrtVal sqrtVal)
1518+ , benchIOSrc1 "concatMapWith (1 of n)"
1519+ (concatMapWithSerial 1 value)
1520+
1521+ -- quadratic with number of outer streams
1522+ , benchIOSrc1 "concatMapWithAppend (2 of n/2)"
15061523 (concatMapWithAppend 2 (value `div` 2))
1524+
1525+ -- concatMap vs concatUnfold
1526+ , benchIOSrc1 "concatMapRepl (sqrt n of sqrt n)"
1527+ (concatMapRepl sqrtVal sqrtVal)
1528+ , benchIOSrc1 "concatUnfoldRepl (sqrt n of sqrt n)"
1529+ (concatUnfoldRepl sqrtVal sqrtVal)
15071530 ]
15081531 ]
15091532
1533+ where
1534+
1535+ sqrtVal = round $ sqrt (fromIntegral value :: Double)
1536+
15101537-------------------------------------------------------------------------------
15111538-- Monad
15121539-------------------------------------------------------------------------------