@@ -17,21 +17,6 @@ import GHC.Exception (ErrorCall)
17import qualified Streamly as S hiding (runStream)
17import qualified Streamly as S hiding (runStream)
18import qualified Streamly.Prelude as S
18import qualified Streamly.Prelude as S
21−#ifdef LONG_BENCHMARKS
22−linearCount = 10000000
29−nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
33−nestedCount3 = round (fromIntegral linearCount**(1/3::Double))
35-------------------------------------------------------------------------------
20-------------------------------------------------------------------------------
36-- Stream generation and elimination
21-- Stream generation and elimination
37-------------------------------------------------------------------------------
22-------------------------------------------------------------------------------
@@ -42,6 +27,7 @@ type Stream m a = S.SerialT m a
42source :: (S.MonadAsync m, S.IsStream t) => Int -> Int -> t m Int
27source :: (S.MonadAsync m, S.IsStream t) => Int -> Int -> t m Int
43source = sourceUnfoldrM
28source = sourceUnfoldrM
30+-- Change this to "sourceUnfoldrM value n" for consistency
45{-# INLINE sourceUnfoldrM #-}
31{-# INLINE sourceUnfoldrM #-}
46sourceUnfoldrM :: (S.IsStream t, S.MonadAsync m) => Int -> Int -> t m Int
32sourceUnfoldrM :: (S.IsStream t, S.MonadAsync m) => Int -> Int -> t m Int
47sourceUnfoldrM n value = S.serially $ S.unfoldrM step n
33sourceUnfoldrM n value = S.serially $ S.unfoldrM step n
@@ -75,89 +61,105 @@ runToList = S.toList
75{-# INLINE toNullAp #-}
61{-# INLINE toNullAp #-}
77 :: (S.IsStream t, S.MonadAsync m, Applicative (t m))
63 :: (S.IsStream t, S.MonadAsync m, Applicative (t m))
78− => (t m Int -> S.SerialT m Int) -> Int -> m ()
64+ => Int -> (t m Int -> S.SerialT m Int) -> Int -> m ()
79−toNullAp t start = runStream . t $
65+toNullAp linearCount t start = runStream . t $
80 (+) <$> source start nestedCount2 <*> source start nestedCount2
66 (+) <$> source start nestedCount2 <*> source start nestedCount2
68+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
82{-# INLINE toNull #-}
70{-# INLINE toNull #-}
84 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
72 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
85− => (t m Int -> S.SerialT m Int) -> Int -> m ()
73+ => Int -> (t m Int -> S.SerialT m Int) -> Int -> m ()
86−toNull t start = runStream . t $ do
74+toNull linearCount t start = runStream . t $ do
87 x <- source start nestedCount2
75 x <- source start nestedCount2
88 y <- source start nestedCount2
76 y <- source start nestedCount2
89 return $ x + y
77 return $ x + y
79+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
91{-# INLINE toNull3 #-}
81{-# INLINE toNull3 #-}
93 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
83 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
94− => (t m Int -> S.SerialT m Int) -> Int -> m ()
84+ => Int -> (t m Int -> S.SerialT m Int) -> Int -> m ()
95−toNull3 t start = runStream . t $ do
85+toNull3 linearCount t start = runStream . t $ do
96 x <- source start nestedCount3
86 x <- source start nestedCount3
97 y <- source start nestedCount3
87 y <- source start nestedCount3
98 z <- source start nestedCount3
88 z <- source start nestedCount3
99 return $ x + y + z
89 return $ x + y + z
91+ nestedCount3 = round (fromIntegral linearCount**(1/3::Double))
101{-# INLINE toList #-}
93{-# INLINE toList #-}
103 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
95 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
104− => (t m Int -> S.SerialT m Int) -> Int -> m [Int]
96+ => Int -> (t m Int -> S.SerialT m Int) -> Int -> m [Int]
105−toList t start = runToList . t $ do
97+toList linearCount t start = runToList . t $ do
106 x <- source start nestedCount2
98 x <- source start nestedCount2
107 y <- source start nestedCount2
99 y <- source start nestedCount2
108 return $ x + y
100 return $ x + y
102+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
110{-# INLINE toListSome #-}
104{-# INLINE toListSome #-}
111toListSome
105toListSome
112 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
106 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
113− => (t m Int -> S.SerialT m Int) -> Int -> m [Int]
107+ => Int -> (t m Int -> S.SerialT m Int) -> Int -> m [Int]
114−toListSome t start =
108+toListSome linearCount t start =
115 runToList . t $ S.take 1000 $ do
109 runToList . t $ S.take 1000 $ do
116 x <- source start nestedCount2
110 x <- source start nestedCount2
117 y <- source start nestedCount2
111 y <- source start nestedCount2
118 return $ x + y
112 return $ x + y
114+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
120{-# INLINE filterAllOut #-}
116{-# INLINE filterAllOut #-}
121filterAllOut
117filterAllOut
122 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
118 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
123− => (t m Int -> S.SerialT m Int) -> Int -> m ()
119+ => Int -> (t m Int -> S.SerialT m Int) -> Int -> m ()
124−filterAllOut t start = runStream . t $ do
120+filterAllOut linearCount t start = runStream . t $ do
125 x <- source start nestedCount2
121 x <- source start nestedCount2
126 y <- source start nestedCount2
122 y <- source start nestedCount2
127 let s = x + y
123 let s = x + y
129 then return s
125 then return s
130 else S.nil
126 else S.nil
128+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
132{-# INLINE filterAllIn #-}
130{-# INLINE filterAllIn #-}
133filterAllIn
131filterAllIn
134 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
132 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
135− => (t m Int -> S.SerialT m Int) -> Int -> m ()
133+ => Int -> (t m Int -> S.SerialT m Int) -> Int -> m ()
136−filterAllIn t start = runStream . t $ do
134+filterAllIn linearCount t start = runStream . t $ do
137 x <- source start nestedCount2
135 x <- source start nestedCount2
138 y <- source start nestedCount2
136 y <- source start nestedCount2
139 let s = x + y
137 let s = x + y
141 then return s
139 then return s
142 else S.nil
140 else S.nil
142+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
144{-# INLINE filterSome #-}
144{-# INLINE filterSome #-}
145filterSome
145filterSome
146 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
146 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
147− => (t m Int -> S.SerialT m Int) -> Int -> m ()
147+ => Int -> (t m Int -> S.SerialT m Int) -> Int -> m ()
148−filterSome t start = runStream . t $ do
148+filterSome linearCount t start = runStream . t $ do
149 x <- source start nestedCount2
149 x <- source start nestedCount2
150 y <- source start nestedCount2
150 y <- source start nestedCount2
151 let s = x + y
151 let s = x + y
152 if s > 1100000
152 if s > 1100000
153 then return s
153 then return s
154 else S.nil
154 else S.nil
156+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
156{-# INLINE breakAfterSome #-}
158{-# INLINE breakAfterSome #-}
157breakAfterSome
159breakAfterSome
158 :: (S.IsStream t, Monad (t IO))
160 :: (S.IsStream t, Monad (t IO))
159− => (t IO Int -> S.SerialT IO Int) -> Int -> IO ()
161+ => Int -> (t IO Int -> S.SerialT IO Int) -> Int -> IO ()
160−breakAfterSome t start = do
162+breakAfterSome linearCount t start = do
161 (_ :: Either ErrorCall ()) <- try $ runStream . t $ do
163 (_ :: Either ErrorCall ()) <- try $ runStream . t $ do
162 x <- source start nestedCount2
164 x <- source start nestedCount2
163 y <- source start nestedCount2
165 y <- source start nestedCount2
@@ -166,3 +168,5 @@ breakAfterSome t start = do
166 then error "break"
168 then error "break"
167 else return s
169 else return s
168 return ()
170 return ()
172+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))