-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ad530b
commit 7a5e58b
Showing
6 changed files
with
117 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Benchmark.Effect where | ||
|
||
import Benchmark.Effect.Output qualified as Output | ||
import Benchmark.Effect.Reader qualified as Reader | ||
import Benchmark.Effect.ReaderH qualified as ReaderH | ||
import Benchmark.Effect.State qualified as State | ||
import Test.Tasty.Bench | ||
|
||
bm :: Benchmark | ||
bm = | ||
bgroup | ||
"Effect" | ||
[ Output.bm, | ||
State.bm, | ||
ReaderH.bm, | ||
Reader.bm | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
module Benchmark.Effect.Reader where | ||
|
||
import Juvix.Prelude | ||
import Juvix.Prelude.Effects (Eff, (:>)) | ||
import Juvix.Prelude.Effects qualified as E | ||
import Test.Tasty.Bench | ||
|
||
bm :: Benchmark | ||
bm = | ||
bgroup | ||
"Reader (First order)" | ||
[ bench "Eff Reader (Static)" $ nf countEff k, | ||
bench "Sem Reader" $ nf countSem k, | ||
bench "Raw Reader" $ nf countRaw k | ||
] | ||
|
||
k :: Natural | ||
k = 2 ^ (21 :: Natural) | ||
|
||
c :: Natural | ||
c = 5 | ||
|
||
countRaw :: Natural -> Natural | ||
countRaw = sum' . go [] | ||
where | ||
i :: Natural = 5 | ||
go :: [Natural] -> Natural -> [Natural] | ||
go acc = \case | ||
0 -> acc | ||
m -> go (i : acc) (pred m) | ||
|
||
countEff :: Natural -> Natural | ||
countEff = sum' . E.runPureEff . E.runReader c . go [] | ||
where | ||
go :: (E.Reader Natural :> r) => [Natural] -> Natural -> Eff r [Natural] | ||
go acc = \case | ||
0 -> return acc | ||
n -> do | ||
i <- E.ask | ||
go (i : acc) (pred n) | ||
|
||
countSem :: Natural -> Natural | ||
countSem = sum' . run . runReader c . go [] | ||
where | ||
go :: (Member (Reader Natural) r) => [Natural] -> Natural -> Sem r [Natural] | ||
go acc = \case | ||
0 -> return acc | ||
n -> do | ||
i <- ask | ||
go (i : acc) (pred n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module Benchmark.Effect.ReaderH where | ||
|
||
import Juvix.Prelude | ||
import Juvix.Prelude.Effects (Eff, (:>)) | ||
import Juvix.Prelude.Effects qualified as E | ||
import Test.Tasty.Bench | ||
|
||
bm :: Benchmark | ||
bm = | ||
bgroup | ||
"Reader (Higher order)" | ||
[ bench "Eff Reader (Static)" $ nf countEff k, | ||
bench "Sem Reader" $ nf countSem k, | ||
bench "Raw Reader" $ nf countRaw k | ||
] | ||
|
||
k :: Natural | ||
k = 2 ^ (21 :: Natural) | ||
|
||
countRaw :: Natural -> Natural | ||
countRaw = sum' . go [] | ||
where | ||
go :: [Natural] -> Natural -> [Natural] | ||
go acc = \case | ||
0 -> acc | ||
m -> go (m : acc) (pred m) | ||
|
||
countEff :: Natural -> Natural | ||
countEff x = sum' . E.runPureEff . E.runReader x $ go [] | ||
where | ||
go :: (E.Reader Natural :> r) => [Natural] -> Eff r [Natural] | ||
go acc = do | ||
n <- E.ask | ||
case n of | ||
0 -> return acc | ||
m -> E.local @Natural pred (go (m : acc)) | ||
|
||
countSem :: Natural -> Natural | ||
countSem x = sum . run . runReader x $ go [] | ||
where | ||
go :: (Members '[Reader Natural] r) => [Natural] -> Sem r [Natural] | ||
go acc = do | ||
n :: Natural <- ask | ||
case n of | ||
0 -> return acc | ||
m -> local @Natural pred (go (m : acc)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
module Main where | ||
|
||
import Benchmark.Output qualified as Output | ||
import Benchmark.State qualified as State | ||
import Benchmark.Effect qualified as Effect | ||
import Juvix.Prelude | ||
import Test.Tasty.Bench | ||
|
||
main :: IO () | ||
main = | ||
defaultMain | ||
[ Output.bm, | ||
State.bm | ||
[ Effect.bm | ||
] |