mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-20 15:05:40 +00:00
Add storage root recalculation time to benchmarks (#5035)
This commit is contained in:
@@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
mod utils;
|
mod utils;
|
||||||
pub use utils::*;
|
pub use utils::*;
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub use sp_io::storage::root as storage_root;
|
||||||
|
|
||||||
/// Construct pallet benchmarks for weighing dispatchables.
|
/// Construct pallet benchmarks for weighing dispatchables.
|
||||||
///
|
///
|
||||||
@@ -177,12 +179,17 @@ macro_rules! impl_benchmark {
|
|||||||
// Commit the externalities to the database, flushing the DB cache.
|
// Commit the externalities to the database, flushing the DB cache.
|
||||||
// This will enable worst case scenario for reading from the database.
|
// This will enable worst case scenario for reading from the database.
|
||||||
$crate::benchmarking::commit_db();
|
$crate::benchmarking::commit_db();
|
||||||
// Run the benchmark.
|
// Time the extrinsic logic.
|
||||||
let start = $crate::benchmarking::current_time();
|
let start_extrinsic = $crate::benchmarking::current_time();
|
||||||
call.dispatch(caller.into())?;
|
call.dispatch(caller.into())?;
|
||||||
let finish = $crate::benchmarking::current_time();
|
let finish_extrinsic = $crate::benchmarking::current_time();
|
||||||
let elapsed = finish - start;
|
let elapsed_extrinsic = finish_extrinsic - start_extrinsic;
|
||||||
results.push((c.clone(), elapsed));
|
// Time the storage root recalculation.
|
||||||
|
let start_storage_root = $crate::benchmarking::current_time();
|
||||||
|
$crate::storage_root();
|
||||||
|
let finish_storage_root = $crate::benchmarking::current_time();
|
||||||
|
let elapsed_storage_root = finish_storage_root - start_storage_root;
|
||||||
|
results.push((c.clone(), elapsed_extrinsic, elapsed_storage_root));
|
||||||
// Wipe the DB back to the genesis state.
|
// Wipe the DB back to the genesis state.
|
||||||
$crate::benchmarking::wipe_db();
|
$crate::benchmarking::wipe_db();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ pub enum BenchmarkParameter {
|
|||||||
/// Results from running benchmarks on a FRAME pallet.
|
/// Results from running benchmarks on a FRAME pallet.
|
||||||
/// Contains duration of the function call in nanoseconds along with the benchmark parameters
|
/// Contains duration of the function call in nanoseconds along with the benchmark parameters
|
||||||
/// used for that benchmark result.
|
/// used for that benchmark result.
|
||||||
pub type BenchmarkResults = (Vec<(BenchmarkParameter, u32)>, u128);
|
pub type BenchmarkResults = (Vec<(BenchmarkParameter, u32)>, u128, u128);
|
||||||
|
|
||||||
sp_api::decl_runtime_apis! {
|
sp_api::decl_runtime_apis! {
|
||||||
/// Runtime api for benchmarking a FRAME runtime.
|
/// Runtime api for benchmarking a FRAME runtime.
|
||||||
|
|||||||
@@ -124,12 +124,13 @@ impl BenchmarkCmd {
|
|||||||
// Print the table header
|
// Print the table header
|
||||||
results[0].0.iter().for_each(|param| print!("{:?},", param.0));
|
results[0].0.iter().for_each(|param| print!("{:?},", param.0));
|
||||||
|
|
||||||
print!("time\n");
|
print!("extrinsic_time,storage_root_time\n");
|
||||||
// Print the values
|
// Print the values
|
||||||
results.iter().for_each(|result| {
|
results.iter().for_each(|result| {
|
||||||
let parameters = &result.0;
|
let parameters = &result.0;
|
||||||
parameters.iter().for_each(|param| print!("{:?},", param.1));
|
parameters.iter().for_each(|param| print!("{:?},", param.1));
|
||||||
print!("{:?}\n", result.1);
|
// Print extrinsic time and storage root time
|
||||||
|
print!("{:?},{:?}\n", result.1, result.2);
|
||||||
});
|
});
|
||||||
|
|
||||||
eprintln!("Done.");
|
eprintln!("Done.");
|
||||||
|
|||||||
Reference in New Issue
Block a user