on master help sign in
Move additional benchmarks under a build flag
53b8da3Harendra Kumar
asyncly.cabal+18−5
@@ -63,6 +63,11 @@ test-suite test
63 transformers >= 0.4 && < 0.6
63 transformers >= 0.4 && < 0.6
64 default-language: Haskell2010
64 default-language: Haskell2010
65
65
66+flag extra-benchmarks
67+ description: Include comparative benchmarks
68+ manual: True
69+ default: False
70+
66benchmark bench
71benchmark bench
67 type: exitcode-stdio-1.0
72 type: exitcode-stdio-1.0
68 main-is: Main.hs
73 main-is: Main.hs
@@ -76,12 +81,20 @@ benchmark bench
76 , atomic-primops >= 0.8 && < 0.9
81 , atomic-primops >= 0.8 && < 0.9
77 , base >= 4.8 && < 5
82 , base >= 4.8 && < 5
78 , criterion >= 1 && < 2
83 , criterion >= 1 && < 2
79− , list-t >= 1 && < 2
80− , logict >= 0.6 && < 0.7
81− , machines >= 0.6 && < 0.7
82 , mtl >= 2.2 && < 3
84 , mtl >= 2.2 && < 3
85+
86+ if impl(ghc < 8.0)
87+ build-depends:
88+ transformers >= 0.4 && < 0.6
89+
90+ if flag(extra-benchmarks)
91+ cpp-options: -DEXTRA_BENCHMARKS
92+ build-depends:
93+ list-t >= 0.4 && < 2
94+ , logict >= 0.6 && < 0.7
95+ , machines >= 0.5 && < 0.7
83− , simple-conduit >= 0.6 && < 0.7
96+ , simple-conduit >= 0.6 && < 0.7
84− , transient >= 0.4 && < 0.6
97+ , transient >= 0.4 && < 0.6
85 default-language: Haskell2010
98 default-language: Haskell2010
86
99
87source-repository head
100source-repository head
benchmark/Main.hs+40−33
@@ -12,6 +12,8 @@ import Data.IORef (IORef, newIORef, writeIORef)
12import System.IO.Unsafe (unsafePerformIO)
12import System.IO.Unsafe (unsafePerformIO)
13
13
14import qualified Asyncly as A
14import qualified Asyncly as A
15+
16+#ifdef EXTRA_BENCHMARKS
15import qualified Conduit.Simple as S
17import qualified Conduit.Simple as S
16import qualified Control.Monad.Logic as LG
18import qualified Control.Monad.Logic as LG
17import qualified Data.Machine as M
19import qualified Data.Machine as M
@@ -20,6 +22,7 @@ import qualified Transient.Internals as T
20import qualified Transient.Indeterminism as T
22import qualified Transient.Indeterminism as T
21#endif
23#endif
22import qualified ListT as LT
24import qualified ListT as LT
25+#endif
23
26
24main :: IO ()
27main :: IO ()
25main = do
28main = do
@@ -33,6 +36,7 @@ main = do
33 , bench "asyncly-interleaved-nil" $ nfIO (asyncly_nil (A.<=>))
36 , bench "asyncly-interleaved-nil" $ nfIO (asyncly_nil (A.<=>))
34 , bench "asyncly-parleft-nil" $ nfIO (asyncly_nil (A.<|))
37 , bench "asyncly-parleft-nil" $ nfIO (asyncly_nil (A.<|))
35 , bench "asyncly-parinterleaved-nil" $ nfIO (asyncly_nil (A.<|>))
38 , bench "asyncly-parinterleaved-nil" $ nfIO (asyncly_nil (A.<|>))
39+#ifdef EXTRA_BENCHMARKS
36#if MIN_VERSION_transient(0,5,1)
40#if MIN_VERSION_transient(0,5,1)
37 , bench "transient" $ nfIO transient_basic
41 , bench "transient" $ nfIO transient_basic
38 , bench "transient-nil" $ nfIO transient_nil
42 , bench "transient-nil" $ nfIO transient_nil
@@ -41,6 +45,7 @@ main = do
41 , bench "list-t" $ nfIO list_t_basic
45 , bench "list-t" $ nfIO list_t_basic
42 , bench "simple-conduit" $ nfIO simple_conduit_basic
46 , bench "simple-conduit" $ nfIO simple_conduit_basic
43 , bench "machines" $ nfIO machines_basic
47 , bench "machines" $ nfIO machines_basic
48+#endif
44 ]
49 ]
45 ]
50 ]
46
51
@@ -64,39 +69,6 @@ drop num x = do
64 guard mn
69 guard mn
65 return x
70 return x
66
71
67−#if MIN_VERSION_transient(0,5,1)
68−tmap :: (a -> Int) -> a -> T.TransIO Int
69−tmap = Main.map
70−
71−tfilter :: (a -> Bool) -> a -> T.TransIO a
72−tfilter = Main.filter
73−
74−tdrop :: Int -> Int -> T.TransIO Int
75−tdrop = Main.drop
76−
77−transient_basic :: IO (Maybe Int)
78−
79−transient_basic = T.keep' $ T.threads 0 $ do
80− liftIO $ writeIORef count 0
81− xs <- T.group 49900 $ do
82− T.choose [1..100000 :: Int]
83− >>= tfilter even
84− >>= tmap (+1)
85− >>= tdrop 100
86− >>= tmap (+1)
87− >>= tfilter (\x -> x `mod` 2 == 0)
88−
89− assert (Prelude.length xs == 49900) $
90− T.exit (Prelude.length xs)
91−
92−transient_nil :: IO (Maybe Int)
93−transient_nil = T.keep' $ T.threads 0 $ do
94− xs <- T.group 49900 $ do
95− T.choose [1..100000 :: Int]
96− assert (Prelude.length xs == 49900) $
97− T.exit (Prelude.length xs)
98−#endif
99−
100amap :: (Int -> Int) -> Int -> A.AsyncT IO Int
72amap :: (Int -> Int) -> Int -> A.AsyncT IO Int
101amap = Main.map
73amap = Main.map
102
74
@@ -132,6 +104,40 @@ asyncly_nil f = do
132 assert (Prelude.length xs == 100000) $
104 assert (Prelude.length xs == 100000) $
133 return (Prelude.length xs)
105 return (Prelude.length xs)
134
106
107+#ifdef EXTRA_BENCHMARKS
108+#if MIN_VERSION_transient(0,5,1)
109+tmap :: (a -> Int) -> a -> T.TransIO Int
110+tmap = Main.map
111+
112+tfilter :: (a -> Bool) -> a -> T.TransIO a
113+tfilter = Main.filter
114+
115+tdrop :: Int -> Int -> T.TransIO Int
116+tdrop = Main.drop
117+
118+transient_basic :: IO (Maybe Int)
119+
120+transient_basic = T.keep' $ T.threads 0 $ do
121+ liftIO $ writeIORef count 0
122+ xs <- T.group 49900 $ do
123+ T.choose [1..100000 :: Int]
124+ >>= tfilter even
125+ >>= tmap (+1)
126+ >>= tdrop 100
127+ >>= tmap (+1)
128+ >>= tfilter (\x -> x `mod` 2 == 0)
129+
130+ assert (Prelude.length xs == 49900) $
131+ T.exit (Prelude.length xs)
132+
133+transient_nil :: IO (Maybe Int)
134+transient_nil = T.keep' $ T.threads 0 $ do
135+ xs <- T.group 49900 $ do
136+ T.choose [1..100000 :: Int]
137+ assert (Prelude.length xs == 49900) $
138+ T.exit (Prelude.length xs)
139+#endif
140+
135lfilter :: (Int -> Bool) -> Int -> LT.ListT IO Int
141lfilter :: (Int -> Bool) -> Int -> LT.ListT IO Int
136lfilter = Main.filter
142lfilter = Main.filter
137
143
@@ -199,3 +205,4 @@ machines_basic = do
199 M.~> M.filtered (\x -> x `mod` 2 == 0)
205 M.~> M.filtered (\x -> x `mod` 2 == 0)
200 assert (Prelude.length xs == 49900) $
206 assert (Prelude.length xs == 49900) $
201 return (Prelude.length (xs ::[Int]))
207 return (Prelude.length (xs ::[Int]))
208+#endif