on master help sign in
Remove cpp-options that control length in nested*
f684e26adithyaov
benchmark/Nested.hs+32−19
@@ -11,6 +11,8 @@ import System.Random (randomRIO)
11import qualified NestedOps as Ops
11import qualified NestedOps as Ops
12import Streamly
12import Streamly
13import Gauge
13import Gauge
14+import System.Environment (getArgs)
15+import Text.Read (readMaybe)
14
16
15benchIO :: (NFData b) => String -> (Int -> IO b) -> Benchmark
17benchIO :: (NFData b) => String -> (Int -> IO b) -> Benchmark
16benchIO name f = bench name $ nfIO $ randomRIO (1,1) >>= f
18benchIO name f = bench name $ nfIO $ randomRIO (1,1) >>= f
@@ -19,34 +21,45 @@ _benchId :: (NFData b) => String -> (Int -> Identity b) -> Benchmark
19_benchId name f = bench name $ nf (\g -> runIdentity (g 1)) f
21_benchId name f = bench name $ nf (\g -> runIdentity (g 1)) f
20
22
21main :: IO ()
23main :: IO ()
22−main =
24+main = do
23 -- TBD Study scaling with 10, 100, 1000 loop iterations
25 -- TBD Study scaling with 10, 100, 1000 loop iterations
24− defaultMain
26+ -- Basement.Terminal.initialize required?
27+ args <- getArgs
28+ let (linearCount, args') = parseValue args
29+ (cfg, extra) = parseWith defaultConfig args'
30+ runMode (mode cfg) cfg extra
25 [ bgroup "serially"
31 [ bgroup "serially"
26− [ benchIO "toNullAp" $ Ops.toNullAp serially
32+ [ benchIO "toNullAp" $ Ops.toNullAp linearCount serially
27− , benchIO "toNull" $ Ops.toNull serially
33+ , benchIO "toNull" $ Ops.toNull linearCount serially
28− , benchIO "toNull3" $ Ops.toNull3 serially
34+ , benchIO "toNull3" $ Ops.toNull3 linearCount serially
29− , benchIO "toList" $ Ops.toList serially
35+ , benchIO "toList" $ Ops.toList linearCount serially
30 -- , benchIO "toListSome" $ Ops.toListSome serially
36 -- , benchIO "toListSome" $ Ops.toListSome serially
31− , benchIO "filterAllOut" $ Ops.filterAllOut serially
37+ , benchIO "filterAllOut" $ Ops.filterAllOut linearCount serially
32− , benchIO "filterAllIn" $ Ops.filterAllIn serially
38+ , benchIO "filterAllIn" $ Ops.filterAllIn linearCount serially
33− , benchIO "filterSome" $ Ops.filterSome serially
39+ , benchIO "filterSome" $ Ops.filterSome linearCount serially
34− , benchIO "breakAfterSome" $ Ops.breakAfterSome serially
40+ , benchIO "breakAfterSome" $ Ops.breakAfterSome linearCount serially
35 ]
41 ]
36
42
37 , bgroup "wSerially"
43 , bgroup "wSerially"
38− [ benchIO "toNullAp" $ Ops.toNullAp wSerially
44+ [ benchIO "toNullAp" $ Ops.toNullAp linearCount wSerially
39− , benchIO "toNull" $ Ops.toNull wSerially
45+ , benchIO "toNull" $ Ops.toNull linearCount wSerially
40− , benchIO "toNull3" $ Ops.toNull3 wSerially
46+ , benchIO "toNull3" $ Ops.toNull3 linearCount wSerially
41− , benchIO "toList" $ Ops.toList wSerially
47+ , benchIO "toList" $ Ops.toList linearCount wSerially
42 -- , benchIO "toListSome" $ Ops.toListSome wSerially
48 -- , benchIO "toListSome" $ Ops.toListSome wSerially
43− , benchIO "filterAllOut" $ Ops.filterAllOut wSerially
49+ , benchIO "filterAllOut" $ Ops.filterAllOut linearCount wSerially
44− , benchIO "filterAllIn" $ Ops.filterAllIn wSerially
50+ , benchIO "filterAllIn" $ Ops.filterAllIn linearCount wSerially
45− , benchIO "filterSome" $ Ops.filterSome wSerially
51+ , benchIO "filterSome" $ Ops.filterSome linearCount wSerially
46− , benchIO "breakAfterSome" $ Ops.breakAfterSome wSerially
52+ , benchIO "breakAfterSome" $ Ops.breakAfterSome linearCount wSerially
47 ]
53 ]
48
54
49 , bgroup "zipSerially"
55 , bgroup "zipSerially"
50− [ benchIO "toNullAp" $ Ops.toNullAp zipSerially
56+ [ benchIO "toNullAp" $ Ops.toNullAp linearCount zipSerially
51 ]
57 ]
52 ]
58 ]
59+ where
60+ defaultValue = 100000
61+ parseValue [] = (defaultValue, [])
62+ parseValue a@(x:xs) =
63+ case (readMaybe x :: Maybe Int) of
64+ Just value -> (value, xs)
65+ Nothing -> (defaultValue, a)
benchmark/NestedConcurrent.hs+48−35
@@ -11,6 +11,8 @@ import System.Random (randomRIO)
11import qualified NestedOps as Ops
11import qualified NestedOps as Ops
12import Streamly
12import Streamly
13import Gauge
13import Gauge
14+import System.Environment (getArgs)
15+import Text.Read (readMaybe)
14
16
15benchIO :: (NFData b) => String -> (Int -> IO b) -> Benchmark
17benchIO :: (NFData b) => String -> (Int -> IO b) -> Benchmark
16benchIO name f = bench name $ nfIO $ randomRIO (1,1) >>= f
18benchIO name f = bench name $ nfIO $ randomRIO (1,1) >>= f
@@ -19,59 +21,70 @@ _benchId :: (NFData b) => String -> (Int -> Identity b) -> Benchmark
19_benchId name f = bench name $ nf (\g -> runIdentity (g 1)) f
21_benchId name f = bench name $ nf (\g -> runIdentity (g 1)) f
20
22
21main :: IO ()
23main :: IO ()
22−main =
24+main = do
23 -- TBD Study scaling with 10, 100, 1000 loop iterations
25 -- TBD Study scaling with 10, 100, 1000 loop iterations
24− defaultMain
26+ -- Basement.Terminal.initialize required?
27+ args <- getArgs
28+ let (linearCount, args') = parseValue args
29+ (cfg, extra) = parseWith defaultConfig args'
30+ runMode (mode cfg) cfg extra
25 [
31 [
26 bgroup "aheadly"
32 bgroup "aheadly"
27− [ benchIO "toNullAp" $ Ops.toNullAp aheadly
33+ [ benchIO "toNullAp" $ Ops.toNullAp linearCount aheadly
28− , benchIO "toNull" $ Ops.toNull aheadly
34+ , benchIO "toNull" $ Ops.toNull linearCount aheadly
29− , benchIO "toNull3" $ Ops.toNull3 aheadly
35+ , benchIO "toNull3" $ Ops.toNull3 linearCount aheadly
30− , benchIO "toList" $ Ops.toList aheadly
36+ , benchIO "toList" $ Ops.toList linearCount aheadly
31 -- , benchIO "toListSome" $ Ops.toListSome aheadly
37 -- , benchIO "toListSome" $ Ops.toListSome aheadly
32− , benchIO "filterAllOut" $ Ops.filterAllOut aheadly
38+ , benchIO "filterAllOut" $ Ops.filterAllOut linearCount aheadly
33− , benchIO "filterAllIn" $ Ops.filterAllIn aheadly
39+ , benchIO "filterAllIn" $ Ops.filterAllIn linearCount aheadly
34− , benchIO "filterSome" $ Ops.filterSome aheadly
40+ , benchIO "filterSome" $ Ops.filterSome linearCount aheadly
35− , benchIO "breakAfterSome" $ Ops.breakAfterSome aheadly
41+ , benchIO "breakAfterSome" $ Ops.breakAfterSome linearCount aheadly
36 ]
42 ]
37
43
38 , bgroup "asyncly"
44 , bgroup "asyncly"
39− [ benchIO "toNullAp" $ Ops.toNullAp asyncly
45+ [ benchIO "toNullAp" $ Ops.toNullAp linearCount asyncly
40− , benchIO "toNull" $ Ops.toNull asyncly
46+ , benchIO "toNull" $ Ops.toNull linearCount asyncly
41− , benchIO "toNull3" $ Ops.toNull3 asyncly
47+ , benchIO "toNull3" $ Ops.toNull3 linearCount asyncly
42− , benchIO "toList" $ Ops.toList asyncly
48+ , benchIO "toList" $ Ops.toList linearCount asyncly
43 -- , benchIO "toListSome" $ Ops.toListSome asyncly
49 -- , benchIO "toListSome" $ Ops.toListSome asyncly
44− , benchIO "filterAllOut" $ Ops.filterAllOut asyncly
50+ , benchIO "filterAllOut" $ Ops.filterAllOut linearCount asyncly
45− , benchIO "filterAllIn" $ Ops.filterAllIn asyncly
51+ , benchIO "filterAllIn" $ Ops.filterAllIn linearCount asyncly
46− , benchIO "filterSome" $ Ops.filterSome asyncly
52+ , benchIO "filterSome" $ Ops.filterSome linearCount asyncly
47− , benchIO "breakAfterSome" $ Ops.breakAfterSome asyncly
53+ , benchIO "breakAfterSome" $ Ops.breakAfterSome linearCount asyncly
48 ]
54 ]
49
55
50 , bgroup "wAsyncly"
56 , bgroup "wAsyncly"
51− [ benchIO "toNullAp" $ Ops.toNullAp wAsyncly
57+ [ benchIO "toNullAp" $ Ops.toNullAp linearCount wAsyncly
52− , benchIO "toNull" $ Ops.toNull wAsyncly
58+ , benchIO "toNull" $ Ops.toNull linearCount wAsyncly
53− , benchIO "toNull3" $ Ops.toNull3 wAsyncly
59+ , benchIO "toNull3" $ Ops.toNull3 linearCount wAsyncly
54− , benchIO "toList" $ Ops.toList wAsyncly
60+ , benchIO "toList" $ Ops.toList linearCount wAsyncly
55 -- , benchIO "toListSome" $ Ops.toListSome wAsyncly
61 -- , benchIO "toListSome" $ Ops.toListSome wAsyncly
56− , benchIO "filterAllOut" $ Ops.filterAllOut wAsyncly
62+ , benchIO "filterAllOut" $ Ops.filterAllOut linearCount wAsyncly
57− , benchIO "filterAllIn" $ Ops.filterAllIn wAsyncly
63+ , benchIO "filterAllIn" $ Ops.filterAllIn linearCount wAsyncly
58− , benchIO "filterSome" $ Ops.filterSome wAsyncly
64+ , benchIO "filterSome" $ Ops.filterSome linearCount wAsyncly
59− , benchIO "breakAfterSome" $ Ops.breakAfterSome wAsyncly
65+ , benchIO "breakAfterSome" $ Ops.breakAfterSome linearCount wAsyncly
60 ]
66 ]
61
67
62 , bgroup "parallely"
68 , bgroup "parallely"
63− [ benchIO "toNullAp" $ Ops.toNullAp parallely
69+ [ benchIO "toNullAp" $ Ops.toNullAp linearCount parallely
64− , benchIO "toNull" $ Ops.toNull parallely
70+ , benchIO "toNull" $ Ops.toNull linearCount parallely
65− , benchIO "toNull3" $ Ops.toNull3 parallely
71+ , benchIO "toNull3" $ Ops.toNull3 linearCount parallely
66− , benchIO "toList" $ Ops.toList parallely
72+ , benchIO "toList" $ Ops.toList linearCount parallely
67 --, benchIO "toListSome" $ Ops.toListSome parallely
73 --, benchIO "toListSome" $ Ops.toListSome parallely
68− , benchIO "filterAllOut" $ Ops.filterAllOut parallely
74+ , benchIO "filterAllOut" $ Ops.filterAllOut linearCount parallely
69− , benchIO "filterAllIn" $ Ops.filterAllIn parallely
75+ , benchIO "filterAllIn" $ Ops.filterAllIn linearCount parallely
70− , benchIO "filterSome" $ Ops.filterSome parallely
76+ , benchIO "filterSome" $ Ops.filterSome linearCount parallely
71− , benchIO "breakAfterSome" $ Ops.breakAfterSome parallely
77+ , benchIO "breakAfterSome" $ Ops.breakAfterSome linearCount parallely
72 ]
78 ]
73
79
74 , bgroup "zipAsyncly"
80 , bgroup "zipAsyncly"
75− [ benchIO "toNullAp" $ Ops.toNullAp zipAsyncly
81+ [ benchIO "toNullAp" $ Ops.toNullAp linearCount zipAsyncly
76 ]
82 ]
77 ]
83 ]
84+ where
85+ defaultValue = 100000
86+ parseValue [] = (defaultValue, [])
87+ parseValue a@(x:xs) =
88+ case (readMaybe x :: Maybe Int) of
89+ Just value -> (value, xs)
90+ Nothing -> (defaultValue, a)
benchmark/NestedOps.hs+37−33
@@ -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
19
19
20−linearCount :: Int
21−#ifdef LONG_BENCHMARKS
22−linearCount = 10000000
23−#else
24−linearCount = 100000
25−#endif
26−
27−-- double nested loop
28−nestedCount2 :: Int
29−nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
30−
31−-- triple nested loop
32−nestedCount3 :: Int
33−nestedCount3 = round (fromIntegral linearCount**(1/3::Double))
34−
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
44
29
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 #-}
76toNullAp
62toNullAp
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
67+ where
68+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
81
69
82{-# INLINE toNull #-}
70{-# INLINE toNull #-}
83toNull
71toNull
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
78+ where
79+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
90
80
91{-# INLINE toNull3 #-}
81{-# INLINE toNull3 #-}
92toNull3
82toNull3
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
90+ where
91+ nestedCount3 = round (fromIntegral linearCount**(1/3::Double))
100
92
101{-# INLINE toList #-}
93{-# INLINE toList #-}
102toList
94toList
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
101+ where
102+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
109
103
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
113+ where
114+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
119
115
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
128 if s < 0
124 if s < 0
129 then return s
125 then return s
130 else S.nil
126 else S.nil
127+ where
128+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
131
129
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
140 if s > 0
138 if s > 0
141 then return s
139 then return s
142 else S.nil
140 else S.nil
141+ where
142+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
143
143
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
155+ where
156+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
155
157
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 ()
171+ where
172+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
streamly.cabal+4−21
@@ -585,10 +585,10 @@ test-suite parallel-loops
585-------------------------------------------------------------------------------
585-------------------------------------------------------------------------------
586
586
587-- NOTE :
587-- NOTE :
588−-- For linear, linear-async and linear-rate if you want to pass the number
588+-- For linear, linear-async, linear-rate, nested and nested-concurrent if you
589−-- of stream elements for benchmarking then you can pass it as the first
589+-- want to pass the number of stream elements for benchmarking, you can pass it
590−-- argument after `--`, as a gauge argument. If you don't give the argument,
590+-- as the first argument after `--`, as a gauge argument. If you don't give the
591−-- the number of stream elements default to 100000.
591+-- argument, the number of stream elements default to 100000.
592-- Examples:
592-- Examples:
593-- $ cabal run linear -- 1000000 [additional gauge options here...]
593-- $ cabal run linear -- 1000000 [additional gauge options here...]
594-- $ cabal run linear -- [additional gauge options here...]
594-- $ cabal run linear -- [additional gauge options here...]
@@ -751,23 +751,6 @@ benchmark nested-concurrent
751 build-depends:
751 build-depends:
752 transformers >= 0.4 && < 0.6
752 transformers >= 0.4 && < 0.6
753
753
754−benchmark nested-concurrent-long
755− import: bench-options-threaded
756− cpp-options: -DLONG_BENCHMARKS
757− type: exitcode-stdio-1.0
758− hs-source-dirs: benchmark
759− main-is: NestedConcurrent.hs
760− other-modules: NestedOps
761− build-depends:
762− streamly
763− , base >= 4.8 && < 5
764− , deepseq >= 1.4.1 && < 1.5
765− , random >= 1.0 && < 2.0
766− , gauge >= 0.2.4 && < 0.3
767− if impl(ghc < 8.0)
768− build-depends:
769− transformers >= 0.4 && < 0.6
770−
771benchmark linear-rate
754benchmark linear-rate
772 import: bench-options-threaded
755 import: bench-options-threaded
773 type: exitcode-stdio-1.0
756 type: exitcode-stdio-1.0