Skip to content

Commit a3d5138

Browse files
authored
bench regular apply vs case apply (#7410)
1 parent ac7745e commit a3d5138

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

plutus-benchmark/casing/bench/Bench.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,17 @@ benchmarks ctx =
3030
, mkBMs "integer" Casing.casingInteger
3131
, mkBMs "list" Casing.casingList
3232
, mkBMs "list one branch" Casing.casingListOneBranch
33+
, mkBMsSmall "regularApply" Casing.regularApply
34+
, mkBMsSmall "caseApply" Casing.caseApply
3335
]
3436
]
3537
where
3638
mkBMs name f =
3739
bgroup name $ [2000, 4000..12000] <&> \n ->
3840
bench (show n) $ benchTermCek ctx (f n)
41+
mkBMsSmall name f =
42+
bgroup name $ [3, 10, 30, 100, 500, 1000] <&> \n ->
43+
bench (show n) $ benchTermCek ctx (f n)
3944

4045
main :: IO ()
4146
main = do

plutus-benchmark/casing/src/PlutusBenchmark/Casing.hs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
module PlutusBenchmark.Casing where
55

6+
import Control.Monad (replicateM)
67
import Control.Monad.Except
78
import Data.Either
89
import PlutusBenchmark.Common (Term)
@@ -203,3 +204,23 @@ headListCasing i =
203204
apply ()
204205
(lamAbs () x intTy t)
205206
(kase () intTy listVal [lamAbs () y intTy $ lamAbs () ys intListTy $ var () y])
207+
208+
regularApply :: Integer -> Term
209+
regularApply i =
210+
debruijnTermUnsafe $
211+
foldl (apply ()) lam (replicate (fromIntegral i) unitVal)
212+
where
213+
unitTy = PLC.mkTyBuiltin @_ @() ()
214+
unitVal = mkConstant @() () ()
215+
lam = runQuote $ do
216+
foldr (\x -> lamAbs () x unitTy) unitVal <$> replicateM (fromIntegral i) (freshName "x")
217+
218+
caseApply :: Integer -> Term
219+
caseApply i =
220+
debruijnTermUnsafe $
221+
kase () unitTy (constr () unitTy 0 (replicate (fromIntegral i) unitVal)) [lam]
222+
where
223+
unitTy = PLC.mkTyBuiltin @_ @() ()
224+
unitVal = mkConstant @() () ()
225+
lam = runQuote $ do
226+
foldr (\x -> lamAbs () x unitTy) unitVal <$> replicateM (fromIntegral i) (freshName "x")

0 commit comments

Comments
 (0)