-
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
c73f7b2
commit 69ce498
Showing
2 changed files
with
51 additions
and
0 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
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,49 @@ | ||
module Benchmark.Effect.EmbedIO where | ||
|
||
import Juvix.Prelude | ||
import Juvix.Prelude.Effects (Eff) | ||
import Juvix.Prelude.Effects qualified as E | ||
import Test.Tasty.Bench | ||
|
||
bm :: Benchmark | ||
bm = | ||
bgroup | ||
"Embed IO" | ||
[ bench "Raw IO" $ nfAppIO countRaw k, | ||
bench "Eff RIO" $ nfAppIO countEff k, | ||
bench "Sem Embed IO" $ nfAppIO countSem k | ||
] | ||
|
||
k :: Natural | ||
k = 2 ^ (23 :: Natural) | ||
|
||
c :: Char | ||
c = 'x' | ||
|
||
countRaw :: Natural -> IO () | ||
countRaw = countHelper | ||
|
||
countHelper :: forall m. (MonadMask m, MonadIO m) => Natural -> m () | ||
countHelper n = | ||
withSystemTempFile "tmp" $ \_ h -> go h n | ||
where | ||
go :: Handle -> Natural -> m () | ||
go h = \case | ||
0 -> return () | ||
a -> liftIO (hPutChar h c) >> go h (pred a) | ||
|
||
countSem :: Natural -> IO () | ||
countSem n = withSystemTempFile "tmp" $ \_ h -> runM (go h n) | ||
where | ||
go :: Handle -> Natural -> Sem '[Embed IO] () | ||
go h = \case | ||
0 -> return () | ||
a -> liftIO (hPutChar h c) >> go h (pred a) | ||
|
||
countEff :: Natural -> IO () | ||
countEff n = withSystemTempFile "tmp" $ \_ h -> E.runEff (go h n) | ||
where | ||
go :: Handle -> Natural -> Eff '[E.IOE] () | ||
go h = \case | ||
0 -> return () | ||
a -> liftIO (hPutChar h c) >> go h (pred a) |