on master help sign in
Added Cabal flags for benchmark suite (#15)

* Added Cabal flags for benchmark suite There is one flag for each effect library. Those flag control whether that benchmark is included or not. * One flag to disable benchmarks of foreign libraries * Do not run foreign benchmarks by default * Control MTL benchmarks with benchmark-foreign-libraries Fixed some unused import warnings * Use less CPP

commitfb883c9aa84f9eef3eff817d55d4d4bdd99cab48 authorMann mit Hut <mmhat@users.noreply.github.com> dateFri 9 Jul 2021, 19:33 (5 years ago) parentc015579
4 files changed+42−11
bench/Countdown.hs+7−1 bench/FileSizes.hs+14−3 bench/Main.hs+8 effectful.cabal+13−7
bench/Countdown.hs+7−1
@@ -2,7 +2,6 @@
22module Countdown where
33
44import Control.Monad.ST
5−import Data.Functor.Identity
65import Data.STRef
76
87-- eff
@@ -32,8 +31,11 @@ import qualified Control.Carrier.State.Strict as FE
3231#endif
3332
3433-- mtl
34+#ifdef VERSION_mtl
3535import qualified Control.Monad.Reader as M
3636import qualified Control.Monad.State as M
37+import Data.Functor.Identity
38+#endif
3739
3840-- polysemy
3941#ifdef VERSION_polysemy
@@ -72,6 +74,8 @@ countdownST n = runST $ do
7274----------------------------------------
7375-- mtl
7476
77+#ifdef VERSION_mtl
78+
7579programMtl :: M.MonadState Integer m => m Integer
7680programMtl = do
7781 n <- M.get @Integer
@@ -94,6 +98,8 @@ countdownMtlDeep n = runIdentity
9498 where
9599 runR = flip M.runReaderT ()
96100
101+#endif
102+
97103----------------------------------------
98104-- effectful (pure)
99105
bench/FileSizes.hs+14−3
@@ -6,7 +6,6 @@ module FileSizes where
66import Control.Exception
77import Control.Monad.IO.Class
88import Data.IORef
9−import Data.Tuple
109import System.Posix
1110
1211-- effectful
@@ -27,8 +26,10 @@ import qualified Control.Monad.Freer.State as FS
2726#endif
2827
2928-- mtl
29+#ifdef VERSION_mtl
3030import qualified Control.Monad.State as M
3131import qualified Control.Monad.Reader as M
32+#endif
3233
3334-- polysemy
3435#ifdef VERSION_polysemy
@@ -155,10 +156,13 @@ eff_runLogging
155156 :: L.Eff (Eff_Logging : es) a
156157 -> L.Eff es (a, [String])
157158eff_runLogging
158− = fmap swap . L.runState [] . L.interpret \case
159+ = fmap eff_swap . L.runState [] . L.interpret \case
159160 Eff_logMsg msg -> L.modify (msg :)
160161 . L.lift
161162
163+eff_swap :: (a, b) -> (b, a)
164+eff_swap (x, y) = (y, x)
165+
162166----------
163167
164168eff_calculateFileSize
@@ -263,6 +267,8 @@ fs_calculateFileSizesDeep = FS.runM
263267----------------------------------------
264268-- mtl
265269
270+#ifdef VERSION_mtl
271+
266272class Monad m => MonadFile m where
267273 mtl_tryFileSize :: FilePath -> m (Maybe Int)
268274
@@ -329,6 +335,8 @@ mtl_calculateFileSizesDeep
329335 where
330336 runR = flip M.runReaderT ()
331337
338+#endif
339+
332340----------------------------------------
333341-- polysemy
334342
@@ -351,9 +359,12 @@ poly_logMsg :: P.Member Poly_Logging es => String -> P.Sem es ()
351359poly_logMsg = P.send . Poly_logMsg
352360
353361poly_runLogging :: P.Sem (Poly_Logging : es) a -> P.Sem es (a, [String])
354−poly_runLogging = fmap swap . P.runState [] . P.reinterpret \case
362+poly_runLogging = fmap poly_swap . P.runState [] . P.reinterpret \case
355363 Poly_logMsg msg -> P.modify (msg :)
356364
365+poly_swap :: (a, b) -> (b, a)
366+poly_swap (x, y) = (y, x)
367+
357368----------
358369
359370poly_calculateFileSize
bench/Main.hs+8
@@ -36,7 +36,9 @@ countdown n = bgroup (show n)
3636#ifdef VERSION_eff
3737 , bench "eff" $ nf countdownEff n
3838#endif
39+#ifdef VERSION_mtl
3940 , bench "mtl" $ nf countdownMtl n
41+#endif
4042#ifdef VERSION_fused_effects
4143 , bench "fused-effects" $ nf countdownFusedEffects n
4244#endif
@@ -58,7 +60,9 @@ countdown n = bgroup (show n)
5860#ifdef VERSION_polysemy
5961 , bench "polysemy" $ nf countdownPolysemyDeep n
6062#endif
63+#ifdef VERSION_mtl
6164 , bench "mtl" $ nf countdownMtlDeep n
65+#endif
6266#ifdef VERSION_fused_effects
6367 , bench "fused-effects" $ nf countdownFusedEffectsDeep n
6468#endif
@@ -73,7 +77,9 @@ filesize n = bgroup (show n)
7377#ifdef VERSION_freer_simple
7478 , bench "freer-simple" $ nfAppIO fs_calculateFileSizes (take n files)
7579#endif
80+#ifdef VERSION_mtl
7681 , bench "mtl" $ nfAppIO mtl_calculateFileSizes (take n files)
82+#endif
7783#ifdef VERSION_eff
7884 , bench "eff" $ nfAppIO eff_calculateFileSizes (take n files)
7985#endif
@@ -92,7 +98,9 @@ filesize n = bgroup (show n)
9298#ifdef VERSION_polysemy
9399 , bench "polysemy" $ nfAppIO poly_calculateFileSizesDeep (take n files)
94100#endif
101+#ifdef VERSION_mtl
95102 , bench "mtl" $ nfAppIO mtl_calculateFileSizesDeep (take n files)
103+#endif
96104 ]
97105 ]
98106 where
effectful.cabal+13−7
@@ -22,6 +22,10 @@ source-repository head
2222 type: git
2323 location: https://github.com/arybczak/effectful.git
2424
25+flag benchmark-foreign-libraries
26+ description: Include other effect libraries in the benchmarks
27+ default: False
28+
2529common language
2630 ghc-options: -Wall -Wcompat
2731
@@ -128,18 +132,20 @@ benchmark bench
128132
129133 ghc-options: -threaded -rtsopts -with-rtsopts=-T
130134
131− if impl(ghc < 9)
132− build-depends: freer-simple
135+ if flag(benchmark-foreign-libraries)
136+ build-depends: mtl
137+
138+ if impl(ghc < 9)
139+ build-depends: freer-simple
133140
134− if impl(ghc < 9.2)
135− build-depends: fused-effects
141+ if impl(ghc < 9.2)
142+ build-depends: fused-effects
136143
137− if impl(ghc < 9)
138− build-depends: polysemy
144+ if impl(ghc < 9)
145+ build-depends: polysemy
139146
140147 build-depends: base <5
141148 , effectful
142− , mtl
143149 , tasty-bench
144150 , transformers
145151 , unix