Skip to content
This repository was archived by the owner on Jul 4, 2022. It is now read-only.

Commit 41bb219

Browse files
authored
Add storage root recalculation time to benchmarks (#5035)
1 parent ddfa359 commit 41bb219

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

frame/benchmarking/src/lib.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
mod utils;
2222
pub use utils::*;
23+
#[doc(hidden)]
24+
pub use sp_io::storage::root as storage_root;
2325

2426
/// Construct pallet benchmarks for weighing dispatchables.
2527
///
@@ -177,12 +179,17 @@ macro_rules! impl_benchmark {
177179
// Commit the externalities to the database, flushing the DB cache.
178180
// This will enable worst case scenario for reading from the database.
179181
$crate::benchmarking::commit_db();
180-
// Run the benchmark.
181-
let start = $crate::benchmarking::current_time();
182+
// Time the extrinsic logic.
183+
let start_extrinsic = $crate::benchmarking::current_time();
182184
call.dispatch(caller.into())?;
183-
let finish = $crate::benchmarking::current_time();
184-
let elapsed = finish - start;
185-
results.push((c.clone(), elapsed));
185+
let finish_extrinsic = $crate::benchmarking::current_time();
186+
let elapsed_extrinsic = finish_extrinsic - start_extrinsic;
187+
// Time the storage root recalculation.
188+
let start_storage_root = $crate::benchmarking::current_time();
189+
$crate::storage_root();
190+
let finish_storage_root = $crate::benchmarking::current_time();
191+
let elapsed_storage_root = finish_storage_root - start_storage_root;
192+
results.push((c.clone(), elapsed_extrinsic, elapsed_storage_root));
186193
// Wipe the DB back to the genesis state.
187194
$crate::benchmarking::wipe_db();
188195
}

frame/benchmarking/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub enum BenchmarkParameter {
3131
/// Results from running benchmarks on a FRAME pallet.
3232
/// Contains duration of the function call in nanoseconds along with the benchmark parameters
3333
/// used for that benchmark result.
34-
pub type BenchmarkResults = (Vec<(BenchmarkParameter, u32)>, u128);
34+
pub type BenchmarkResults = (Vec<(BenchmarkParameter, u32)>, u128, u128);
3535

3636
sp_api::decl_runtime_apis! {
3737
/// Runtime api for benchmarking a FRAME runtime.

utils/frame/benchmarking-cli/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,13 @@ impl BenchmarkCmd {
124124
// Print the table header
125125
results[0].0.iter().for_each(|param| print!("{:?},", param.0));
126126

127-
print!("time\n");
127+
print!("extrinsic_time,storage_root_time\n");
128128
// Print the values
129129
results.iter().for_each(|result| {
130130
let parameters = &result.0;
131131
parameters.iter().for_each(|param| print!("{:?},", param.1));
132-
print!("{:?}\n", result.1);
132+
// Print extrinsic time and storage root time
133+
print!("{:?},{:?}\n", result.1, result.2);
133134
});
134135

135136
eprintln!("Done.");

0 commit comments

Comments
 (0)