You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
icToRawTuple (InsertCoinBenchmark(PolicyId p) (TokenName t) (Amount a) v) = (p, t, a, v)
40
53
41
54
benchInsertCoin::StdGen->Benchmark
42
55
benchInsertCoin gen =
43
56
createFourTermBuiltinBenchElementwiseWithWrappers
44
57
(id, id, id, id) -- TODO: use proper wrappers
45
58
InsertCoin
46
59
[]
47
-
(icToTuple<$> insertCoinBenchGen gen)
60
+
(icToRawTuple<$> insertCoinBenchGen gen)
48
61
49
62
--| Generate a set of benchmarks for the InsertCoin builtin function.
50
63
-- It includes the following scenarios:
51
64
-- 1. Inserting into an empty Value.
52
-
-- 2. Inserting a new TokenName into an existing PolicyId.
53
-
-- 3. Inserting into an existing TokenName.
65
+
-- 2. Inserting a new TokenName into an existing PolicyId. Randomly extracting a PolicyId from the Value.
66
+
-- 3. Inserting into an existing TokenName. Randomly extracting a (PolicyId, TokenName) pair from the Value.
54
67
-- 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.
68
+
-- 5. Deleting a TokenName by inserting a 0 amount. Randomly extracting a (PolicyId, TokenName) pair from the Value.
69
+
-- 6. Deleting a PolicyId by inserting a 0 amount into its last TokenName. Should generate a Value with multiple such PolicyIds, and randomly picking which PolicyId to delete.
57
70
-- We're interested in the worst case performance, so we'll use the largest key values possible.
71
+
-- Each one of the cases should be applied to monotonically increasing sizes of the Value.
72
+
-- We should also run randomized benchmarks, where we insert random values into random Values.
58
73
insertCoinBenchGen
59
74
::StdGen
60
75
-> [InsertCoinBenchmark]
61
-
insertCoinBenchGen g =undefined
76
+
insertCoinBenchGen g =flip evalState (GenState00) $ runStateGenT_ g $\gen ->do
77
+
policyId <- newPolicyId gen
78
+
tokenName <- newTokenName gen
79
+
amount <- uniformAmount gen
80
+
let emptyValueBench =InsertCoinBenchmark policyId tokenName amount Value.empty
81
+
pure [emptyValueBench]
82
+
83
+
--| Generate a unique PolicyId on a uniform distribution. Note that the size of the
84
+
-- generated bytestring is going to be larger than Value.maxKeyLen, because we
85
+
-- append a counter integer to ensure uniqueness. This is acceptable for benchmarking
86
+
-- purposes, as we're interested in the worst-case performance.
87
+
newPolicyId::StateGenMStdGen->BenchStatePolicyId
88
+
newPolicyId gen =do
89
+
bs <- uniformByteStringM Value.maxKeyLen gen
90
+
c <- lift $ gets policyIdCounter
91
+
let newbs =BS.append bs (encodeUtf8 .Text.pack .show$ c)
92
+
lift $ modify $\s -> s { policyIdCounter = c +1 }
93
+
pure$PolicyId newbs
94
+
95
+
--| Generate a unique TokenName on a uniform distribution. Note that the size of the
96
+
-- generated bytestring is going to be larger than Value.maxKeyLen, because we
97
+
-- append a counter integer to ensure uniqueness. This is acceptable for benchmarking
98
+
-- purposes, as we're interested in the worst-case performance.
0 commit comments