on master help sign in
Remove cpp-options that control length in nested*

* This includes nested, nested-concurrent * Modules removed: nested-concurrent-long * CPP options removed: -DLONG_BENCHMARKS

commitf684e266af1ebc9b964cad541bd254e23027fd00 authoradithyaov <adi.obilisetty@gmail.com> dateFri 3 Jan 2020, 15:07 (7 years ago) parent65ed762
4 files changed+121−108
benchmark/Nested.hs+32−19 benchmark/NestedConcurrent.hs+48−35 benchmark/NestedOps.hs+37−33 streamly.cabal+4−21
benchmark/Nested.hs+32−19
@@ -11,6 +11,8 @@ import System.Random (randomRIO)
1111import qualified NestedOps as Ops
1212import Streamly
1313import Gauge
14+import System.Environment (getArgs)
15+import Text.Read (readMaybe)
1416
1517benchIO :: (NFData b) => String -> (Int -> IO b) -> Benchmark
1618benchIO name f = bench name $ nfIO $ randomRIO (1,1) >>= f
@@ -19,34 +21,45 @@ _benchId :: (NFData b) => String -> (Int -> Identity b) -> Benchmark
1921_benchId name f = bench name $ nf (\g -> runIdentity (g 1)) f
2022
2123main :: IO ()
22−main =
24+main = do
2325 -- 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
2531 [ bgroup "serially"
26− [ benchIO "toNullAp" $ Ops.toNullAp serially
27− , benchIO "toNull" $ Ops.toNull serially
28− , benchIO "toNull3" $ Ops.toNull3 serially
29− , benchIO "toList" $ Ops.toList serially
32+ [ benchIO "toNullAp" $ Ops.toNullAp linearCount serially
33+ , benchIO "toNull" $ Ops.toNull linearCount serially
34+ , benchIO "toNull3" $ Ops.toNull3 linearCount serially
35+ , benchIO "toList" $ Ops.toList linearCount serially
3036 -- , benchIO "toListSome" $ Ops.toListSome serially
31− , benchIO "filterAllOut" $ Ops.filterAllOut serially
32− , benchIO "filterAllIn" $ Ops.filterAllIn serially
33− , benchIO "filterSome" $ Ops.filterSome serially
34− , benchIO "breakAfterSome" $ Ops.breakAfterSome serially
37+ , benchIO "filterAllOut" $ Ops.filterAllOut linearCount serially
38+ , benchIO "filterAllIn" $ Ops.filterAllIn linearCount serially
39+ , benchIO "filterSome" $ Ops.filterSome linearCount serially
40+ , benchIO "breakAfterSome" $ Ops.breakAfterSome linearCount serially
3541 ]
3642
3743 , bgroup "wSerially"
38− [ benchIO "toNullAp" $ Ops.toNullAp wSerially
39− , benchIO "toNull" $ Ops.toNull wSerially
40− , benchIO "toNull3" $ Ops.toNull3 wSerially
41− , benchIO "toList" $ Ops.toList wSerially
44+ [ benchIO "toNullAp" $ Ops.toNullAp linearCount wSerially
45+ , benchIO "toNull" $ Ops.toNull linearCount wSerially
46+ , benchIO "toNull3" $ Ops.toNull3 linearCount wSerially
47+ , benchIO "toList" $ Ops.toList linearCount wSerially
4248 -- , benchIO "toListSome" $ Ops.toListSome wSerially
43− , benchIO "filterAllOut" $ Ops.filterAllOut wSerially
44− , benchIO "filterAllIn" $ Ops.filterAllIn wSerially
45− , benchIO "filterSome" $ Ops.filterSome wSerially
46− , benchIO "breakAfterSome" $ Ops.breakAfterSome wSerially
49+ , benchIO "filterAllOut" $ Ops.filterAllOut linearCount wSerially
50+ , benchIO "filterAllIn" $ Ops.filterAllIn linearCount wSerially
51+ , benchIO "filterSome" $ Ops.filterSome linearCount wSerially
52+ , benchIO "breakAfterSome" $ Ops.breakAfterSome linearCount wSerially
4753 ]
4854
4955 , bgroup "zipSerially"
50− [ benchIO "toNullAp" $ Ops.toNullAp zipSerially
56+ [ benchIO "toNullAp" $ Ops.toNullAp linearCount zipSerially
5157 ]
5258 ]
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)
1111import qualified NestedOps as Ops
1212import Streamly
1313import Gauge
14+import System.Environment (getArgs)
15+import Text.Read (readMaybe)
1416
1517benchIO :: (NFData b) => String -> (Int -> IO b) -> Benchmark
1618benchIO name f = bench name $ nfIO $ randomRIO (1,1) >>= f
@@ -19,59 +21,70 @@ _benchId :: (NFData b) => String -> (Int -> Identity b) -> Benchmark
1921_benchId name f = bench name $ nf (\g -> runIdentity (g 1)) f
2022
2123main :: IO ()
22−main =
24+main = do
2325 -- 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
2531 [
2632 bgroup "aheadly"
27− [ benchIO "toNullAp" $ Ops.toNullAp aheadly
28− , benchIO "toNull" $ Ops.toNull aheadly
29− , benchIO "toNull3" $ Ops.toNull3 aheadly
30− , benchIO "toList" $ Ops.toList aheadly
33+ [ benchIO "toNullAp" $ Ops.toNullAp linearCount aheadly
34+ , benchIO "toNull" $ Ops.toNull linearCount aheadly
35+ , benchIO "toNull3" $ Ops.toNull3 linearCount aheadly
36+ , benchIO "toList" $ Ops.toList linearCount aheadly
3137 -- , benchIO "toListSome" $ Ops.toListSome aheadly
32− , benchIO "filterAllOut" $ Ops.filterAllOut aheadly
33− , benchIO "filterAllIn" $ Ops.filterAllIn aheadly
34− , benchIO "filterSome" $ Ops.filterSome aheadly
35− , benchIO "breakAfterSome" $ Ops.breakAfterSome aheadly
38+ , benchIO "filterAllOut" $ Ops.filterAllOut linearCount aheadly
39+ , benchIO "filterAllIn" $ Ops.filterAllIn linearCount aheadly
40+ , benchIO "filterSome" $ Ops.filterSome linearCount aheadly
41+ , benchIO "breakAfterSome" $ Ops.breakAfterSome linearCount aheadly
3642 ]
3743
3844 , bgroup "asyncly"
39− [ benchIO "toNullAp" $ Ops.toNullAp asyncly
40− , benchIO "toNull" $ Ops.toNull asyncly
41− , benchIO "toNull3" $ Ops.toNull3 asyncly
42− , benchIO "toList" $ Ops.toList asyncly
45+ [ benchIO "toNullAp" $ Ops.toNullAp linearCount asyncly
46+ , benchIO "toNull" $ Ops.toNull linearCount asyncly
47+ , benchIO "toNull3" $ Ops.toNull3 linearCount asyncly
48+ , benchIO "toList" $ Ops.toList linearCount asyncly
4349 -- , benchIO "toListSome" $ Ops.toListSome asyncly
44− , benchIO "filterAllOut" $ Ops.filterAllOut asyncly
45− , benchIO "filterAllIn" $ Ops.filterAllIn asyncly
46− , benchIO "filterSome" $ Ops.filterSome asyncly
47− , benchIO "breakAfterSome" $ Ops.breakAfterSome asyncly
50+ , benchIO "filterAllOut" $ Ops.filterAllOut linearCount asyncly
51+ , benchIO "filterAllIn" $ Ops.filterAllIn linearCount asyncly
52+ , benchIO "filterSome" $ Ops.filterSome linearCount asyncly
53+ , benchIO "breakAfterSome" $ Ops.breakAfterSome linearCount asyncly
4854 ]
4955
5056 , bgroup "wAsyncly"
51− [ benchIO "toNullAp" $ Ops.toNullAp wAsyncly
52− , benchIO "toNull" $ Ops.toNull wAsyncly
53− , benchIO "toNull3" $ Ops.toNull3 wAsyncly
54− , benchIO "toList" $ Ops.toList wAsyncly
57+ [ benchIO "toNullAp" $ Ops.toNullAp linearCount wAsyncly
58+ , benchIO "toNull" $ Ops.toNull linearCount wAsyncly
59+ , benchIO "toNull3" $ Ops.toNull3 linearCount wAsyncly
60+ , benchIO "toList" $ Ops.toList linearCount wAsyncly
5561 -- , benchIO "toListSome" $ Ops.toListSome wAsyncly
56− , benchIO "filterAllOut" $ Ops.filterAllOut wAsyncly
57− , benchIO "filterAllIn" $ Ops.filterAllIn wAsyncly
58− , benchIO "filterSome" $ Ops.filterSome wAsyncly
59− , benchIO "breakAfterSome" $ Ops.breakAfterSome wAsyncly
62+ , benchIO "filterAllOut" $ Ops.filterAllOut linearCount wAsyncly
63+ , benchIO "filterAllIn" $ Ops.filterAllIn linearCount wAsyncly
64+ , benchIO "filterSome" $ Ops.filterSome linearCount wAsyncly
65+ , benchIO "breakAfterSome" $ Ops.breakAfterSome linearCount wAsyncly
6066 ]
6167
6268 , bgroup "parallely"
63− [ benchIO "toNullAp" $ Ops.toNullAp parallely
64− , benchIO "toNull" $ Ops.toNull parallely
65− , benchIO "toNull3" $ Ops.toNull3 parallely
66− , benchIO "toList" $ Ops.toList parallely
69+ [ benchIO "toNullAp" $ Ops.toNullAp linearCount parallely
70+ , benchIO "toNull" $ Ops.toNull linearCount parallely
71+ , benchIO "toNull3" $ Ops.toNull3 linearCount parallely
72+ , benchIO "toList" $ Ops.toList linearCount parallely
6773 --, benchIO "toListSome" $ Ops.toListSome parallely
68− , benchIO "filterAllOut" $ Ops.filterAllOut parallely
69− , benchIO "filterAllIn" $ Ops.filterAllIn parallely
70− , benchIO "filterSome" $ Ops.filterSome parallely
71− , benchIO "breakAfterSome" $ Ops.breakAfterSome parallely
74+ , benchIO "filterAllOut" $ Ops.filterAllOut linearCount parallely
75+ , benchIO "filterAllIn" $ Ops.filterAllIn linearCount parallely
76+ , benchIO "filterSome" $ Ops.filterSome linearCount parallely
77+ , benchIO "breakAfterSome" $ Ops.breakAfterSome linearCount parallely
7278 ]
7379
7480 , bgroup "zipAsyncly"
75− [ benchIO "toNullAp" $ Ops.toNullAp zipAsyncly
81+ [ benchIO "toNullAp" $ Ops.toNullAp linearCount zipAsyncly
7682 ]
7783 ]
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)
1717import qualified Streamly as S hiding (runStream)
1818import qualified Streamly.Prelude as S
1919
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−
3520-------------------------------------------------------------------------------
3621-- Stream generation and elimination
3722-------------------------------------------------------------------------------
@@ -42,6 +27,7 @@ type Stream m a = S.SerialT m a
4227source :: (S.MonadAsync m, S.IsStream t) => Int -> Int -> t m Int
4328source = sourceUnfoldrM
4429
30+-- Change this to "sourceUnfoldrM value n" for consistency
4531{-# INLINE sourceUnfoldrM #-}
4632sourceUnfoldrM :: (S.IsStream t, S.MonadAsync m) => Int -> Int -> t m Int
4733sourceUnfoldrM n value = S.serially $ S.unfoldrM step n
@@ -75,89 +61,105 @@ runToList = S.toList
7561{-# INLINE toNullAp #-}
7662toNullAp
7763 :: (S.IsStream t, S.MonadAsync m, Applicative (t m))
78− => (t m Int -> S.SerialT m Int) -> Int -> m ()
79−toNullAp t start = runStream . t $
64+ => Int -> (t m Int -> S.SerialT m Int) -> Int -> m ()
65+toNullAp linearCount t start = runStream . t $
8066 (+) <$> source start nestedCount2 <*> source start nestedCount2
67+ where
68+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
8169
8270{-# INLINE toNull #-}
8371toNull
8472 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
85− => (t m Int -> S.SerialT m Int) -> Int -> m ()
86−toNull t start = runStream . t $ do
73+ => Int -> (t m Int -> S.SerialT m Int) -> Int -> m ()
74+toNull linearCount t start = runStream . t $ do
8775 x <- source start nestedCount2
8876 y <- source start nestedCount2
8977 return $ x + y
78+ where
79+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
9080
9181{-# INLINE toNull3 #-}
9282toNull3
9383 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
94− => (t m Int -> S.SerialT m Int) -> Int -> m ()
95−toNull3 t start = runStream . t $ do
84+ => Int -> (t m Int -> S.SerialT m Int) -> Int -> m ()
85+toNull3 linearCount t start = runStream . t $ do
9686 x <- source start nestedCount3
9787 y <- source start nestedCount3
9888 z <- source start nestedCount3
9989 return $ x + y + z
90+ where
91+ nestedCount3 = round (fromIntegral linearCount**(1/3::Double))
10092
10193{-# INLINE toList #-}
10294toList
10395 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
104− => (t m Int -> S.SerialT m Int) -> Int -> m [Int]
105−toList t start = runToList . t $ do
96+ => Int -> (t m Int -> S.SerialT m Int) -> Int -> m [Int]
97+toList linearCount t start = runToList . t $ do
10698 x <- source start nestedCount2
10799 y <- source start nestedCount2
108100 return $ x + y
101+ where
102+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
109103
110104{-# INLINE toListSome #-}
111105toListSome
112106 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
113− => (t m Int -> S.SerialT m Int) -> Int -> m [Int]
114−toListSome t start =
107+ => Int -> (t m Int -> S.SerialT m Int) -> Int -> m [Int]
108+toListSome linearCount t start =
115109 runToList . t $ S.take 1000 $ do
116110 x <- source start nestedCount2
117111 y <- source start nestedCount2
118112 return $ x + y
113+ where
114+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
119115
120116{-# INLINE filterAllOut #-}
121117filterAllOut
122118 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
123− => (t m Int -> S.SerialT m Int) -> Int -> m ()
124−filterAllOut t start = runStream . t $ do
119+ => Int -> (t m Int -> S.SerialT m Int) -> Int -> m ()
120+filterAllOut linearCount t start = runStream . t $ do
125121 x <- source start nestedCount2
126122 y <- source start nestedCount2
127123 let s = x + y
128124 if s < 0
129125 then return s
130126 else S.nil
127+ where
128+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
131129
132130{-# INLINE filterAllIn #-}
133131filterAllIn
134132 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
135− => (t m Int -> S.SerialT m Int) -> Int -> m ()
136−filterAllIn t start = runStream . t $ do
133+ => Int -> (t m Int -> S.SerialT m Int) -> Int -> m ()
134+filterAllIn linearCount t start = runStream . t $ do
137135 x <- source start nestedCount2
138136 y <- source start nestedCount2
139137 let s = x + y
140138 if s > 0
141139 then return s
142140 else S.nil
141+ where
142+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
143143
144144{-# INLINE filterSome #-}
145145filterSome
146146 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
147− => (t m Int -> S.SerialT m Int) -> Int -> m ()
148−filterSome t start = runStream . t $ do
147+ => Int -> (t m Int -> S.SerialT m Int) -> Int -> m ()
148+filterSome linearCount t start = runStream . t $ do
149149 x <- source start nestedCount2
150150 y <- source start nestedCount2
151151 let s = x + y
152152 if s > 1100000
153153 then return s
154154 else S.nil
155+ where
156+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
155157
156158{-# INLINE breakAfterSome #-}
157159breakAfterSome
158160 :: (S.IsStream t, Monad (t IO))
159− => (t IO Int -> S.SerialT IO Int) -> Int -> IO ()
160−breakAfterSome t start = do
161+ => Int -> (t IO Int -> S.SerialT IO Int) -> Int -> IO ()
162+breakAfterSome linearCount t start = do
161163 (_ :: Either ErrorCall ()) <- try $ runStream . t $ do
162164 x <- source start nestedCount2
163165 y <- source start nestedCount2
@@ -166,3 +168,5 @@ breakAfterSome t start = do
166168 then error "break"
167169 else return s
168170 return ()
171+ where
172+ nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
streamly.cabal+4−21
@@ -585,10 +585,10 @@ test-suite parallel-loops
585585-------------------------------------------------------------------------------
586586
587587-- NOTE :
588−-- For linear, linear-async and linear-rate if you want to pass the number
589−-- of stream elements for benchmarking then you can pass it as the first
590−-- argument after `--`, as a gauge argument. If you don't give the argument,
591−-- the number of stream elements default to 100000.
588+-- For linear, linear-async, linear-rate, nested and nested-concurrent if you
589+-- want to pass the number of stream elements for benchmarking, you can pass it
590+-- as the first argument after `--`, as a gauge argument. If you don't give the
591+-- argument, the number of stream elements default to 100000.
592592-- Examples:
593593-- $ cabal run linear -- 1000000 [additional gauge options here...]
594594-- $ cabal run linear -- [additional gauge options here...]
@@ -751,23 +751,6 @@ benchmark nested-concurrent
751751 build-depends:
752752 transformers >= 0.4 && < 0.6
753753
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−
771754benchmark linear-rate
772755 import: bench-options-threaded
773756 type: exitcode-stdio-1.0