Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heftia countdown benchmarks #241

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion effectful-th/effectful-th.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ library
, effectful-core >= 1.0.0.0 && < 3.0.0.0
, exceptions >= 0.10.4
, template-haskell >= 2.16 && < 2.23
, th-abstraction >= 0.6 && < 0.8
, th-abstraction >= 0.4 && < 0.8

hs-source-dirs: src

Expand Down
61 changes: 60 additions & 1 deletion effectful/bench/Countdown.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE PackageImports #-}
module Countdown where

import Control.Monad.ST
Expand Down Expand Up @@ -27,7 +28,7 @@ import Effectful.State.Static.Shared qualified as ES

-- freer-simple
#ifdef VERSION_freer_simple
import Control.Monad.Freer qualified as FS
import "freer-simple" Control.Monad.Freer qualified as FS
import Control.Monad.Freer.Reader qualified as FS
import Control.Monad.Freer.State qualified as FS
#endif
Expand All @@ -39,6 +40,17 @@ import Control.Carrier.Reader qualified as FE
import Control.Carrier.State.Strict qualified as FE
#endif

-- heftia
#ifdef VERSION_heftia_effects
import Control.Effect qualified as H
import Control.Effect.ExtensibleChurch qualified as HC
import Control.Effect.ExtensibleFinal qualified as HF
import Control.Effect.ExtensibleTree qualified as HT
import Control.Effect.Interpreter.Heftia.Reader qualified as H
import Control.Effect.Interpreter.Heftia.State qualified as H
import Data.Effect.State qualified as H
#endif

-- mtl
#ifdef VERSION_mtl
import Control.Monad.Reader qualified as M
Expand Down Expand Up @@ -396,6 +408,53 @@ countdownFusedEffectsDeep n = FE.run

#endif

----------------------------------------
-- heftia

#ifdef VERSION_heftia_effects

programHeftia :: (H.State Integer H.<: m, Monad m) => m Integer
programHeftia = do
n <- H.get @Integer
if n <= 0
then pure n
else do
H.put (n - 1)
programHeftia
{-# NOINLINE programHeftia #-}

countdownHeftiaChurch :: Integer -> (Integer, Integer)
countdownHeftiaChurch n = runIdentity . HC.runEff . H.runState n $ programHeftia

countdownHeftiaChurchDeep :: Integer -> (Integer, Integer)
countdownHeftiaChurchDeep n = runIdentity . HC.runEff
. H.runAsk () . H.runAsk () . H.runAsk () . H.runAsk () . H.runAsk ()
. H.runState n
. H.runAsk () . H.runAsk () . H.runAsk () . H.runAsk () . H.runAsk ()
$ programHeftia

countdownHeftiaFinal :: Integer -> (Integer, Integer)
countdownHeftiaFinal n = runIdentity . HF.runEff . H.runState n $ programHeftia

countdownHeftiaFinalDeep :: Integer -> (Integer, Integer)
countdownHeftiaFinalDeep n = runIdentity . HF.runEff
. H.runAsk () . H.runAsk () . H.runAsk () . H.runAsk () . H.runAsk ()
. H.runState n
. H.runAsk () . H.runAsk () . H.runAsk () . H.runAsk () . H.runAsk ()
$ programHeftia

countdownHeftiaTree :: Integer -> (Integer, Integer)
countdownHeftiaTree n = runIdentity . HT.runEff . H.runState n $ programHeftia

countdownHeftiaTreeDeep :: Integer -> (Integer, Integer)
countdownHeftiaTreeDeep n = runIdentity . HT.runEff
. H.runAsk () . H.runAsk () . H.runAsk () . H.runAsk () . H.runAsk ()
. H.runState n
. H.runAsk () . H.runAsk () . H.runAsk () . H.runAsk () . H.runAsk ()
$ programHeftia

#endif

----------------------------------------
-- polysemy

Expand Down
3 changes: 2 additions & 1 deletion effectful/bench/FileSizes.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE PackageImports #-}
{-# LANGUAGE UndecidableInstances #-}
module FileSizes where

Expand Down Expand Up @@ -30,7 +31,7 @@ import Cleff.State qualified as C

-- freer-simple
#ifdef VERSION_freer_simple
import Control.Monad.Freer qualified as FS
import "freer-simple" Control.Monad.Freer qualified as FS
import Control.Monad.Freer.Reader qualified as FS
import Control.Monad.Freer.State qualified as FS
#endif
Expand Down
14 changes: 14 additions & 0 deletions effectful/bench/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ countdown n = bgroup (show n)
, bench "deep" $ nf countdownMtlDeep n
]
#endif
#ifdef VERSION_heftia_effects
, bgroup "heftia-effects (church)"
[ bench "shallow" $ nf countdownHeftiaChurch n
, bench "deep" $ nf countdownHeftiaChurchDeep n
]
, bgroup "heftia-effects (final)"
[ bench "shallow" $ nf countdownHeftiaFinal n
, bench "deep" $ nf countdownHeftiaFinalDeep n
]
, bgroup "heftia-effects (tree)"
[ bench "shallow" $ nf countdownHeftiaTree n
, bench "deep" $ nf countdownHeftiaTreeDeep n
]
#endif
#ifdef VERSION_fused_effects
, bgroup "fused-effects"
[ bench "shallow" $ nf countdownFusedEffects n
Expand Down
6 changes: 6 additions & 0 deletions effectful/effectful.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ benchmark bench
if impl(ghc < 9.11)
build-depends: polysemy >= 1.9.2.0

if impl(ghc < 9.11)
build-depends: data-effects >= 0.1.2.0
, data-effects-core >= 0.1.0.0
, heftia >= 0.3.1.0
, heftia-effects >= 0.3.1.0

build-depends: base
, async
, effectful
Expand Down
Loading