Skip to content

Commit 5033d01

Browse files
committed
Tmp: add benchmark generators
1 parent 0429991 commit 5033d01

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
module Benchmarks.Values (
2+
makeBenchmarks,
3+
) where
4+
5+
import Prelude
6+
7+
import Common
8+
9+
import PlutusCore (DefaultFun (InsertCoin, LookupCoin, UnValueData, ValueContains, ValueData))
10+
import PlutusCore.Value (Value)
11+
import PlutusCore.Value qualified as Value
12+
13+
import Control.Monad.State (State)
14+
import Criterion.Main (Benchmark)
15+
import Data.ByteString (ByteString)
16+
import System.Random.Stateful (StageGenM, StatefulGen, StdGen, UniformRange (uniformRM),
17+
runStateGen_, uniformByteStringM)
18+
19+
makeBenchmarks :: StdGen -> [Benchmark]
20+
makeBenchmarks gen =
21+
[ benchInsertCoin gen
22+
-- , benchUnionValue gen
23+
]
24+
25+
type PolicyId = ByteString
26+
type TokenName = ByteString
27+
type Amount = Integer
28+
29+
-- | An insertCoin benchmark is a concrete set of arguments we apply to the
30+
-- InsertCoin builtin function to measure its runtime cost.
31+
data InsertCoinBenchmark = InsertCoinBenchmark
32+
{ icPolicyId :: PolicyId
33+
, icTokenName :: TokenName
34+
, icAmount :: Amount
35+
, icValue :: Value
36+
}
37+
38+
icToTuple :: InsertCoinBenchmark -> (PolicyId, TokenName, Amount, Value)
39+
icToTuple (InsertCoinBenchmark p t a v) = (p, t, a, v)
40+
41+
benchInsertCoin :: StdGen -> Benchmark
42+
benchInsertCoin gen =
43+
createFourTermBuiltinBenchElementwiseWithWrappers
44+
(id, id, id, id) -- TODO: use proper wrappers
45+
InsertCoin
46+
[]
47+
(icToTuple <$> insertCoinBenchGen gen)
48+
49+
-- | Generate a set of benchmarks for the InsertCoin builtin function.
50+
-- It includes the following scenarios:
51+
-- 1. Inserting into an empty Value.
52+
-- 2. Inserting a new TokenName into an existing PolicyId.
53+
-- 3. Inserting into an existing TokenName.
54+
-- 4. Inserting a new PolicyId.
55+
-- 5. Deleting a TokenName by inserting a 0 amount.
56+
-- 6. Deleting a PolicyId by inserting a 0 amount into its last TokenName.
57+
-- We're interested in the worst case performance, so we'll use the largest key values possible.
58+
insertCoinBenchGen
59+
:: StdGen
60+
-> [InsertCoinBenchmark]
61+
insertCoinBenchGen g = undefined
62+
63+
uniformByteString :: StdGen -> ByteString
64+
uniformByteString gen = uniformByteString Value.maxKeyLen gen

plutus-core/plutus-core.cabal

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ library
9595
Data.MultiSet.Lens
9696
Data.Version.Extras
9797
PlutusCore
98-
PlutusCore.AstSize
9998
PlutusCore.Analysis.Definitions
10099
PlutusCore.Annotation
101100
PlutusCore.Arity
101+
PlutusCore.AstSize
102102
PlutusCore.Bitwise
103103
PlutusCore.Builtin
104104
PlutusCore.Builtin.Debug
@@ -515,11 +515,11 @@ library plutus-ir
515515
hs-source-dirs: plutus-ir/src
516516
exposed-modules:
517517
PlutusIR
518-
PlutusIR.AstSize
519518
PlutusIR.Analysis.Builtins
520519
PlutusIR.Analysis.Dependencies
521520
PlutusIR.Analysis.RetainedSize
522521
PlutusIR.Analysis.VarInfo
522+
PlutusIR.AstSize
523523
PlutusIR.Check.Uniques
524524
PlutusIR.Compiler
525525
PlutusIR.Compiler.Datatype
@@ -935,6 +935,7 @@ executable cost-model-budgeting-bench
935935
Benchmarks.Strings
936936
Benchmarks.Tracing
937937
Benchmarks.Unit
938+
Benchmarks.Values
938939
Common
939940
CriterionExtensions
940941
Generators

0 commit comments

Comments
 (0)