Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions effectful/bench/Countdown.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,30 @@ programMtl = do
programMtl
{-# NOINLINE programMtl #-}

countdownMtl :: Integer -> (Integer, Integer)
countdownMtl n = flip M.runState n $ programMtl
countdownMtlTransformers :: Integer -> (Integer, Integer)
countdownMtlTransformers n = flip M.runState n $ programMtl

countdownMtlDeep :: Integer -> (Integer, Integer)
countdownMtlDeep n = runIdentity
countdownMtlTransformersDeep :: Integer -> (Integer, Integer)
countdownMtlTransformersDeep n = runIdentity
. runR . runR . runR . runR . runR
. flip M.runStateT n
. runR . runR . runR . runR . runR
$ programMtl
where
runR = flip M.runReaderT ()

countdownMtlEffectful :: Integer -> (Integer, Integer)
countdownMtlEffectful n = E.runPureEff . ED.runStateLocal n $ programMtl

countdownMtlEffectfulDeep :: Integer -> (Integer, Integer)
countdownMtlEffectfulDeep n = E.runPureEff
. runR . runR . runR . runR . runR
. ED.runStateLocal n
. runR . runR . runR . runR . runR
$ programMtl
where
runR = E.runReader ()

#endif

----------------------------------------
Expand Down
27 changes: 23 additions & 4 deletions effectful/bench/FileSizes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ fe_calculateFileSizesDeep
class Monad m => MonadFile m where
mtl_tryFileSize :: FilePath -> m (Maybe Int)

instance Effectful_File E.:> es => MonadFile (E.Eff es) where
mtl_tryFileSize = effectful_tryFileSize

newtype FileT m a = FileT { runFileT :: m a }
deriving newtype (Functor, Applicative, Monad, MonadIO)

Expand All @@ -457,6 +460,9 @@ instance MonadIO m => MonadFile (FileT m) where
class Monad m => MonadLog m where
mtl_logMsg :: String -> m ()

instance Effectful_Logging E.:> es => MonadLog (E.Eff es) where
mtl_logMsg = effectful_logMsg

newtype LoggingT m a = LoggingT (M.StateT [Text] m a)
deriving newtype (Functor, Applicative, Monad, MonadIO, M.MonadTrans)

Expand Down Expand Up @@ -491,18 +497,31 @@ mtl_program files = do
pure $ sum sizes
{-# NOINLINE mtl_program #-}

mtl_calculateFileSizes :: [FilePath] -> IO (Int, [Text])
mtl_calculateFileSizes = runFileT . runLoggingT . mtl_program
mtl_calculateFileSizesTransformers :: [FilePath] -> IO (Int, [Text])
mtl_calculateFileSizesTransformers = runFileT . runLoggingT . mtl_program

mtl_calculateFileSizesDeep :: [FilePath] -> IO (Int, [Text])
mtl_calculateFileSizesDeep
mtl_calculateFileSizesTransformersDeep :: [FilePath] -> IO (Int, [Text])
mtl_calculateFileSizesTransformersDeep
= runR . runR . runR . runR . runR
. runFileT . runLoggingT
. runR . runR . runR . runR . runR
. mtl_program
where
runR = flip M.runReaderT ()

mtl_calculateFileSizesEffectful :: [FilePath] -> IO (Int, [Text])
mtl_calculateFileSizesEffectful =
E.runEff . effectful_runFile . effectful_runLogging . mtl_program

mtl_calculateFileSizesEffectfulDeep :: [FilePath] -> IO (Int, [Text])
mtl_calculateFileSizesEffectfulDeep = E.runEff
. runR . runR . runR . runR . runR
. effectful_runFile . effectful_runLogging
. runR . runR . runR . runR . runR
. mtl_program
where
runR = E.runReader ()

#endif

----------------------------------------
Expand Down
20 changes: 14 additions & 6 deletions effectful/bench/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,13 @@ countdown n = bgroup (show n)
]
#endif
#ifdef VERSION_mtl
, bgroup "mtl"
[ bench "shallow" $ nf countdownMtl n
, bench "deep" $ nf countdownMtlDeep n
, bgroup "mtl (transformers)"
[ bench "shallow" $ nf countdownMtlTransformers n
, bench "deep" $ nf countdownMtlTransformersDeep n
]
, bgroup "mtl (effectful)"
[ bench "shallow" $ nf countdownMtlEffectful n
, bench "deep" $ nf countdownMtlEffectfulDeep n
]
#endif
#ifdef VERSION_fused_effects
Expand Down Expand Up @@ -148,9 +152,13 @@ filesize n = bgroup (show n)
]
#endif
#ifdef VERSION_mtl
, bgroup "mtl"
[ bench "shallow" $ nfAppIO mtl_calculateFileSizes (take n files)
, bench "deep" $ nfAppIO mtl_calculateFileSizesDeep (take n files)
, bgroup "mtl (transformers)"
[ bench "shallow" $ nfAppIO mtl_calculateFileSizesTransformers (take n files)
, bench "deep" $ nfAppIO mtl_calculateFileSizesTransformersDeep (take n files)
]
, bgroup "mtl (effectful)"
[ bench "shallow" $ nfAppIO mtl_calculateFileSizesEffectful (take n files)
, bench "deep" $ nfAppIO mtl_calculateFileSizesEffectfulDeep (take n files)
]
#endif
#ifdef VERSION_fused_effects
Expand Down
Loading