A Pallet for Benchmarking Common Runtime Operations (#4902)

* Benchmark pallet

* Add a bunch more benchmarks

* do nothing test

* new benchmarks

* Clean up extra tests

* Encode and Decode Vec<T::AccountId>

* Starting to migrate benchmarks to macro

* Use macro

* Remove call and storage

* Update Cargo.toml

* Add storage recalc benchmark

* Add support for custom functions in benchmark! macro

* Reset DB for storage recalc

* Feedback from review

* Add more comments

* Remove benchmark pallet from node

* Fix cargo files

* Fix comments

* Change `crate` to `super`

* missed one

* Use results of benchmark encode/decode

* Pass generic to extra functions

* reset macro to master

* Update lib.rs

* Update to use standard syntax
This commit is contained in:
Shawn Tabrizi
2020-03-04 18:21:42 +02:00
committed by GitHub
parent e366b5bd2c
commit 3d6329a22d
11 changed files with 359 additions and 8 deletions
+4 -3
View File
@@ -23,6 +23,7 @@ mod utils;
pub use utils::*;
#[doc(hidden)]
pub use sp_io::storage::root as storage_root;
pub use sp_runtime::traits::Dispatchable;
/// Construct pallet benchmarks for weighing dispatchables.
///
@@ -79,14 +80,14 @@ pub use sp_io::storage::root as storage_root;
/// }
///
/// // first dispatchable: foo; this is a user dispatchable and operates on a `u8` vector of
/// // size `l`, which we allow to be initialised as usual.
/// // size `l`, which we allow to be initialized as usual.
/// foo {
/// let caller = account::<T>(b"caller", 0, benchmarks_seed);
/// let l = ...;
/// }: _(Origin::Signed(caller), vec![0u8; l])
///
/// // second dispatchable: bar; this is a root dispatchable and accepts a `u8` vector of size
/// // `l`. We don't want it preininitialised like before so we override using the `=> ()` notation.
/// // `l`. We don't want it pre-initialized like before so we override using the `=> ()` notation.
/// // In this case, we explicitly name the call using `bar` instead of `_`.
/// bar {
/// let l = _ .. _ => ();
@@ -157,7 +158,7 @@ macro_rules! benchmarks_iter {
) => {
$crate::benchmarks_iter! {
{ $( $common )* } ( $( $names )* ) $name { $( $code )* }: {
Call::<T>::$dispatch($($arg),*).dispatch($origin.into())?;
<Call<T> as $crate::Dispatchable>::dispatch(Call::<T>::$dispatch($($arg),*), $origin.into())?;
} $( $rest )*
}
};