Skip to content

Commit d2c34c8

Browse files
authored
Merge pull request #2200 from AleoHQ/benches/transfer-priv
Expands benches on execute
2 parents a0ffabd + e01bbce commit d2c34c8

File tree

1 file changed

+70
-25
lines changed

1 file changed

+70
-25
lines changed

ledger/benches/transaction.rs

Lines changed: 70 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -92,34 +92,79 @@ fn execute(c: &mut Criterion) {
9292
let address = Address::try_from(&private_key).unwrap();
9393

9494
// Initialize the VM.
95-
let (vm, _records) = initialize_vm(&private_key, rng);
96-
97-
// Prepare the inputs.
98-
let inputs =
99-
[Value::<Testnet3>::from_str(&address.to_string()).unwrap(), Value::<Testnet3>::from_str("1u64").unwrap()]
100-
.into_iter();
101-
102-
// Authorize the execution.
103-
let execute_authorization = vm.authorize(&private_key, "credits.aleo", "transfer_public", inputs, rng).unwrap();
104-
// Retrieve the execution ID.
105-
let execution_id = execute_authorization.to_execution_id().unwrap();
106-
// Authorize the fee.
107-
let fee_authorization = vm.authorize_fee_public(&private_key, 300000, 1000, execution_id, rng).unwrap();
108-
109-
c.bench_function("Transaction::Execute(transfer_public)", |b| {
110-
b.iter(|| {
111-
vm.execute_authorization(execute_authorization.replicate(), Some(fee_authorization.replicate()), None, rng)
95+
let (vm, records) = initialize_vm(&private_key, rng);
96+
97+
{
98+
// Prepare the inputs.
99+
let inputs =
100+
[Value::<Testnet3>::from_str(&address.to_string()).unwrap(), Value::<Testnet3>::from_str("1u64").unwrap()]
101+
.into_iter();
102+
103+
// Authorize the execution.
104+
let execute_authorization = vm.authorize(&private_key, "credits.aleo", "transfer_public", inputs, rng).unwrap();
105+
// Retrieve the execution ID.
106+
let execution_id = execute_authorization.to_execution_id().unwrap();
107+
// Authorize the fee.
108+
let fee_authorization = vm.authorize_fee_public(&private_key, 300000, 1000, execution_id, rng).unwrap();
109+
110+
c.bench_function("Transaction::Execute(transfer_public)", |b| {
111+
b.iter(|| {
112+
vm.execute_authorization(
113+
execute_authorization.replicate(),
114+
Some(fee_authorization.replicate()),
115+
None,
116+
rng,
117+
)
112118
.unwrap();
113-
})
114-
});
119+
})
120+
});
121+
122+
let transaction = vm
123+
.execute_authorization(execute_authorization.replicate(), Some(fee_authorization.replicate()), None, rng)
124+
.unwrap();
125+
126+
c.bench_function("Transaction::Execute(transfer_public) - verify", |b| {
127+
b.iter(|| vm.check_transaction(&transaction, None, rng).unwrap())
128+
});
129+
}
130+
131+
{
132+
// Prepare the inputs.
133+
let inputs = [
134+
Value::<Testnet3>::Record(records[0].clone()),
135+
Value::<Testnet3>::from_str(&address.to_string()).unwrap(),
136+
Value::<Testnet3>::from_str("1u64").unwrap(),
137+
]
138+
.into_iter();
139+
140+
// Authorize the execution.
141+
let execute_authorization =
142+
vm.authorize(&private_key, "credits.aleo", "transfer_private", inputs, rng).unwrap();
143+
// Retrieve the execution ID.
144+
let execution_id = execute_authorization.to_execution_id().unwrap();
145+
// Authorize the fee.
146+
let fee_authorization = vm.authorize_fee_public(&private_key, 300000, 1000, execution_id, rng).unwrap();
147+
148+
c.bench_function("Transaction::Execute(transfer_private)", |b| {
149+
b.iter(|| {
150+
vm.execute_authorization(
151+
execute_authorization.replicate(),
152+
Some(fee_authorization.replicate()),
153+
None,
154+
rng,
155+
)
156+
.unwrap();
157+
})
158+
});
115159

116-
let transaction = vm
117-
.execute_authorization(execute_authorization.replicate(), Some(fee_authorization.replicate()), None, rng)
118-
.unwrap();
160+
let transaction = vm
161+
.execute_authorization(execute_authorization.replicate(), Some(fee_authorization.replicate()), None, rng)
162+
.unwrap();
119163

120-
c.bench_function("Transaction::Execute(transfer_public) - verify", |b| {
121-
b.iter(|| vm.check_transaction(&transaction, None, rng).unwrap())
122-
});
164+
c.bench_function("Transaction::Execute(transfer_private) - verify", |b| {
165+
b.iter(|| vm.check_transaction(&transaction, None, rng).unwrap())
166+
});
167+
}
123168
}
124169

125170
criterion_group! {

0 commit comments

Comments
 (0)