@@ -13,20 +13,18 @@ import Streamly.Internal.Data.Unfold (Unfold)
1313import qualified Streamly.Internal.Data.Unfold as UF
1414import qualified Streamly.Internal.Data.Fold as FL
1515
16−linearCount :: Int
17−linearCount = 100000
18−
1916-- n * (n + 1) / 2 == linearCount
20−concatCount :: Int
21−concatCount = 450
17+concatCount :: Int -> Int
18+concatCount linearCount =
19+ round (((1 + 8 * fromIntegral linearCount)**(1/2::Double) - 1) / 2)
2220
2321-- double nested loop
24−nestedCount2 :: Int
25−nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
22+nestedCount2 :: Int -> Int
23+nestedCount2 linearCount = round (fromIntegral linearCount**(1/2::Double))
2624
2725-- triple nested loop
28−nestedCount3 :: Int
29−nestedCount3 = round (fromIntegral linearCount**(1/3::Double))
26+nestedCount3 :: Int -> Int
27+nestedCount3 linearCount = round (fromIntegral linearCount**(1/3::Double))
3028
3129-------------------------------------------------------------------------------
3230-- Stream generation and elimination
@@ -42,18 +40,18 @@ source n = UF.enumerateFromToIntegral n
4240-------------------------------------------------------------------------------
4341
4442{-# INLINE toNull #-}
45−toNull :: MonadIO m => Int -> m ()
46−toNull start = do
47− let end = start + nestedCount2
43+toNull :: MonadIO m => Int -> Int -> m ()
44+toNull linearCount start = do
45+ let end = start + nestedCount2 linearCount
4846 UF.fold
4947 (UF.map (\(x, y) -> x + y)
5048 $ UF.outerProduct (source end) (source end))
5149 FL.drain (start, start)
5250
5351{-# INLINE toNull3 #-}
54−toNull3 :: MonadIO m => Int -> m ()
55−toNull3 start = do
56− let end = start + nestedCount3
52+toNull3 :: MonadIO m => Int -> Int -> m ()
53+toNull3 linearCount start = do
54+ let end = start + nestedCount3 linearCount
5755 UF.fold
5856 (UF.map (\(x, y) -> x + y)
5957 $ UF.outerProduct (source end)
@@ -62,35 +60,35 @@ toNull3 start = do
6260 FL.drain (start, (start, start))
6361
6462{-# INLINE concat #-}
65−concat :: MonadIO m => Int -> m ()
66−concat start = do
67− let end = start + concatCount
63+concat :: MonadIO m => Int -> Int -> m ()
64+concat linearCount start = do
65+ let end = start + concatCount linearCount
6866 UF.fold
6967 (UF.concat (source end) (source end))
7068 FL.drain start
7169
7270{-# INLINE toList #-}
73−toList :: MonadIO m => Int -> m [Int]
74−toList start = do
75− let end = start + nestedCount2
71+toList :: MonadIO m => Int -> Int -> m [Int]
72+toList linearCount start = do
73+ let end = start + nestedCount2 linearCount
7674 UF.fold
7775 (UF.map (\(x, y) -> x + y)
7876 $ UF.outerProduct (source end) (source end))
7977 FL.toList (start, start)
8078
8179{-# INLINE toListSome #-}
82−toListSome :: MonadIO m => Int -> m [Int]
83−toListSome start = do
84− let end = start + nestedCount2
80+toListSome :: MonadIO m => Int -> Int -> m [Int]
81+toListSome linearCount start = do
82+ let end = start + nestedCount2 linearCount
8583 UF.fold
8684 (UF.take 1000 $ (UF.map (\(x, y) -> x + y)
8785 $ UF.outerProduct (source end) (source end)))
8886 FL.toList (start, start)
8987
9088{-# INLINE filterAllOut #-}
91−filterAllOut :: MonadIO m => Int -> m ()
92−filterAllOut start = do
93− let end = start + nestedCount2
89+filterAllOut :: MonadIO m => Int -> Int -> m ()
90+filterAllOut linearCount start = do
91+ let end = start + nestedCount2 linearCount
9492 UF.fold
9593 (UF.filter (< 0)
9694 $ UF.map (\(x, y) -> x + y)
@@ -98,9 +96,9 @@ filterAllOut start = do
9896 FL.drain (start, start)
9997
10098{-# INLINE filterAllIn #-}
101−filterAllIn :: MonadIO m => Int -> m ()
102−filterAllIn start = do
103− let end = start + nestedCount2
99+filterAllIn :: MonadIO m => Int -> Int -> m ()
100+filterAllIn linearCount start = do
101+ let end = start + nestedCount2 linearCount
104102 UF.fold
105103 (UF.filter (> 0)
106104 $ UF.map (\(x, y) -> x + y)
@@ -108,9 +106,9 @@ filterAllIn start = do
108106 FL.drain (start, start)
109107
110108{-# INLINE filterSome #-}
111−filterSome :: MonadIO m => Int -> m ()
112−filterSome start = do
113− let end = start + nestedCount2
109+filterSome :: MonadIO m => Int -> Int -> m ()
110+filterSome linearCount start = do
111+ let end = start + nestedCount2 linearCount
114112 UF.fold
115113 (UF.filter (> 1100000)
116114 $ UF.map (\(x, y) -> x + y)
@@ -118,9 +116,9 @@ filterSome start = do
118116 FL.drain (start, start)
119117
120118{-# INLINE breakAfterSome #-}
121−breakAfterSome :: MonadIO m => Int -> m ()
122−breakAfterSome start = do
123− let end = start + nestedCount2
119+breakAfterSome :: MonadIO m => Int -> Int -> m ()
120+breakAfterSome linearCount start = do
121+ let end = start + nestedCount2 linearCount
124122 UF.fold
125123 (UF.takeWhile (<= 1100000)
126124 $ UF.map (\(x, y) -> x + y)