From dc20db9970d9c5b3d12f5aa106d2b4cc382c8792 Mon Sep 17 00:00:00 2001 From: Stanly Johnson Date: Fri, 25 Dec 2020 00:50:52 +0530 Subject: [PATCH 01/14] commented use of common --- frame/benchmarking/src/lib.rs | 104 ++++++++++++++++---------------- frame/benchmarking/src/tests.rs | 10 +-- 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/frame/benchmarking/src/lib.rs b/frame/benchmarking/src/lib.rs index 6296c000e289f..08556e938ffca 100644 --- a/frame/benchmarking/src/lib.rs +++ b/frame/benchmarking/src/lib.rs @@ -178,16 +178,16 @@ macro_rules! benchmarks { ( $( where_clause { where $( $where_ty:ty: $where_bound:path ),* $(,)? } )? _ { - $( - let $common:ident in $common_from:tt .. $common_to:expr => $common_instancer:expr; - )* + // // // $( + // // // let $common:ident in $common_from:tt .. $common_to:expr => $common_instancer:expr; + // // // )* } $( $rest:tt )* ) => { $crate::benchmarks_iter!( { } { $( $( $where_ty: $where_bound ),* )? } - { $( { $common , $common_from , $common_to , $common_instancer } )* } + //{ $( { $common , $common_from , $common_to , $common_instancer } )* } ( ) ( ) $( $rest )* @@ -225,7 +225,7 @@ macro_rules! benchmarks_iter { ( { $( $instance:ident )? } { $( $where_clause:tt )* } - { $( $common:tt )* } + //{ $( $common:tt )* } ( $( $names:tt )* ) ( $( $names_extra:tt )* ) #[extra] @@ -235,7 +235,7 @@ macro_rules! benchmarks_iter { $crate::benchmarks_iter! { { $( $instance)? } { $( $where_clause )* } - { $( $common )* } + //{ $( $common )* } ( $( $names )* ) ( $( $names_extra )* $name ) $name @@ -246,7 +246,7 @@ macro_rules! benchmarks_iter { ( { $( $instance:ident )? } { $( $where_clause:tt )* } - { $( $common:tt )* } + //{ $( $common:tt )* } ( $( $names:tt )* ) // This contains $( $( { $instance } )? $name:ident )* ( $( $names_extra:tt )* ) $name:ident { $( $code:tt )* }: _ ( $origin:expr $( , $arg:expr )* ) @@ -256,7 +256,7 @@ macro_rules! benchmarks_iter { $crate::benchmarks_iter! { { $( $instance)? } { $( $where_clause )* } - { $( $common )* } + //{ $( $common )* } ( $( $names )* ) ( $( $names_extra )* ) $name { $( $code )* }: $name ( $origin $( , $arg )* ) @@ -268,7 +268,7 @@ macro_rules! benchmarks_iter { ( { $( $instance:ident )? } { $( $where_clause:tt )* } - { $( $common:tt )* } + //{ $( $common:tt )* } ( $( $names:tt )* ) ( $( $names_extra:tt )* ) $name:ident { $( $code:tt )* }: $dispatch:ident ( $origin:expr $( , $arg:expr )* ) @@ -278,7 +278,7 @@ macro_rules! benchmarks_iter { $crate::benchmarks_iter! { { $( $instance)? } { $( $where_clause )* } - { $( $common )* } + //{ $( $common )* } ( $( $names )* ) ( $( $names_extra )* ) $name { $( $code )* }: { @@ -296,7 +296,7 @@ macro_rules! benchmarks_iter { ( { $( $instance:ident )? } { $( $where_clause:tt )* } - { $( $common:tt )* } + //{ $( $common:tt )* } ( $( $names:tt )* ) ( $( $names_extra:tt )* ) $name:ident { $( $code:tt )* }: $eval:block @@ -307,7 +307,7 @@ macro_rules! benchmarks_iter { { $( $instance)? } $name { $( $where_clause )* } - { $( $common )* } + //{ $( $common )* } { } { $eval } { $( $code )* } @@ -324,7 +324,7 @@ macro_rules! benchmarks_iter { $crate::benchmarks_iter!( { $( $instance)? } { $( $where_clause )* } - { $( $common )* } + //{ $( $common )* } ( $( $names )* { $( $instance )? } $name ) ( $( $names_extra )* ) $( $rest )* @@ -334,7 +334,7 @@ macro_rules! benchmarks_iter { ( { $( $instance:ident )? } { $( $where_clause:tt )* } - { $( $common:tt )* } + //{ $( $common:tt )* } ( $( $names:tt )* ) ( $( $names_extra:tt )* ) ) => { @@ -354,7 +354,7 @@ macro_rules! benchmarks_iter { ( { $( $instance:ident )? } { $( $where_clause:tt )* } - { $( $common:tt )* } + //{ $( $common:tt )* } ( $( $names:tt )* ) ( $( $names_extra:tt )* ) $name:ident { $( $code:tt )* }: _ ( $origin:expr $( , $arg:expr )* ) @@ -363,7 +363,7 @@ macro_rules! benchmarks_iter { $crate::benchmarks_iter! { { $( $instance)? } { $( $where_clause )* } - { $( $common )* } + //{ $( $common )* } ( $( $names )* ) ( $( $names_extra )* ) $name { $( $code )* }: _ ( $origin $( , $arg )* ) @@ -375,7 +375,7 @@ macro_rules! benchmarks_iter { ( { $( $instance:ident )? } { $( $where_clause:tt )* } - { $( $common:tt )* } + //{ $( $common:tt )* } ( $( $names:tt )* ) ( $( $names_extra:tt )* ) $name:ident { $( $code:tt )* }: $dispatch:ident ( $origin:expr $( , $arg:expr )* ) @@ -384,7 +384,7 @@ macro_rules! benchmarks_iter { $crate::benchmarks_iter! { { $( $instance)? } { $( $where_clause )* } - { $( $common )* } + //{ $( $common )* } ( $( $names )* ) ( $( $names_extra )* ) $name { $( $code )* }: $dispatch ( $origin $( , $arg )* ) @@ -396,7 +396,7 @@ macro_rules! benchmarks_iter { ( { $( $instance:ident )? } { $( $where_clause:tt )* } - { $( $common:tt )* } + //{ $( $common:tt )* } ( $( $names:tt )* ) ( $( $names_extra:tt )* ) $name:ident { $( $code:tt )* }: $eval:block @@ -405,7 +405,7 @@ macro_rules! benchmarks_iter { $crate::benchmarks_iter!( { $( $instance)? } { $( $where_clause )* } - { $( $common )* } + //{ $( $common )* } ( $( $names )* ) ( $( $names_extra )* ) $name { $( $code )* }: $eval @@ -423,7 +423,7 @@ macro_rules! benchmark_backend { { $( $instance:ident )? } $name:ident { $( $where_clause:tt )* } - { $( $common:tt )* } + //{ $( $common:tt )* } { $( PRE { $( $pre_parsed:tt )* } )* } { $eval:block } { @@ -436,7 +436,7 @@ macro_rules! benchmark_backend { { $( $instance)? } $name { $( $where_clause )* } - { $( $common )* } + //{ $( $common )* } { $( PRE { $( $pre_parsed )* } )* PRE { $pre_id , $pre_ty , $pre_ex } @@ -450,7 +450,7 @@ macro_rules! benchmark_backend { { $( $instance:ident )? } $name:ident { $( $where_clause:tt )* } - { $( $common:tt )* } + //{ $( $common:tt )* } { $( $parsed:tt )* } { $eval:block } { @@ -463,7 +463,7 @@ macro_rules! benchmark_backend { { $( $instance)? } $name { $( $where_clause )* } - { $( $common )* } + //{ $( $common )* } { $( $parsed )* PARAM { $param , $param_from , $param_to , $param_instancer } @@ -478,7 +478,7 @@ macro_rules! benchmark_backend { { $( $instance:ident )? } $name:ident { $( $where_clause:tt )* } - { $( { $common:ident , $common_from:tt , $common_to:expr , $common_instancer:expr } )* } + //{ $( { $common:ident , $common_from:tt , $common_to:expr , $common_instancer:expr } )* } { $( $parsed:tt )* } { $eval:block } { @@ -491,16 +491,16 @@ macro_rules! benchmark_backend { { $( $instance)? } $name { $( $where_clause )* } - { $( { $common , $common_from , $common_to , $common_instancer } )* } + //{ $( { $common , $common_from , $common_to , $common_instancer } )* } { $( $parsed )* } { $eval } - { - let $param - in ({ $( let $common = $common_from; )* $param }) - .. ({ $( let $common = $common_to; )* $param }) - => ({ $( let $common = || -> Result<(), &'static str> { $common_instancer ; Ok(()) }; )* $param()? }); - $( $rest )* - } + // { + // let $param + // in ({ $( let $common = $common_from; )* $param }) + // .. ({ $( let $common = $common_to; )* $param }) + // => ({ $( let $common = || -> Result<(), &'static str> { $common_instancer ; Ok(()) }; )* $param()? }); + // $( $rest )* + // } $postcode } }; @@ -509,7 +509,7 @@ macro_rules! benchmark_backend { { $( $instance:ident )? } $name:ident { $( $where_clause:tt )* } - { $( { $common:ident , $common_from:tt , $common_to:expr , $common_instancer:expr } )* } + //{ $( { $common:ident , $common_from:tt , $common_to:expr , $common_instancer:expr } )* } { $( $parsed:tt )* } { $eval:block } { @@ -522,16 +522,16 @@ macro_rules! benchmark_backend { { $( $instance)? } $name { $( $where_clause )* } - { $( { $common , $common_from , $common_to , $common_instancer } )* } + //{ $( { $common , $common_from , $common_to , $common_instancer } )* } { $( $parsed )* } { $eval } - { - let $param - in ({ $( let $common = $common_from; )* $param }) - .. ({ $( let $common = $common_to; )* $param }) - => $param_instancer ; - $( $rest )* - } + // { + // let $param + // in ({ $( let $common = $common_from; )* $param }) + // .. ({ $( let $common = $common_to; )* $param }) + // => $param_instancer ; + // $( $rest )* + // } $postcode } }; @@ -540,7 +540,7 @@ macro_rules! benchmark_backend { { $( $instance:ident )? } $name:ident { $( $where_clause:tt )* } - { $( $common:tt )* } + //{ $( $common:tt )* } { $( $parsed:tt )* } { $eval:block } { @@ -553,7 +553,7 @@ macro_rules! benchmark_backend { { $( $instance)? } $name { $( $where_clause )* } - { $( $common )* } + //{ $( $common )* } { $( $parsed )* } { $eval } { @@ -568,7 +568,7 @@ macro_rules! benchmark_backend { { $( $instance:ident )? } $name:ident { $( $where_clause:tt )* } - { $( $common:tt )* } + //{ $( $common:tt )* } { $( $parsed:tt )* } { $eval:block } { @@ -581,7 +581,7 @@ macro_rules! benchmark_backend { { $( $instance)? } $name { $( $where_clause )* } - { $( $common )* } + //{ $( $common )* } { $( $parsed )* } { $eval } { @@ -596,7 +596,7 @@ macro_rules! benchmark_backend { { $( $instance:ident )? } $name:ident { $( $where_clause:tt )* } - { $( $common:tt )* } + //{ $( $common:tt )* } { $( $parsed:tt )* } { $eval:block } { @@ -609,7 +609,7 @@ macro_rules! benchmark_backend { { $( $instance)? } $name { $( $where_clause )* } - { $( $common )* } + //{ $( $common )* } { $( $parsed )* } { $eval } { @@ -624,7 +624,7 @@ macro_rules! benchmark_backend { { $( $instance:ident )? } $name:ident { $( $where_clause:tt )* } - { $( { $common:ident , $common_from:tt , $common_to:expr , $common_instancer:expr } )* } + //{ $( { $common:ident , $common_from:tt , $common_to:expr , $common_instancer:expr } )* } { $( PRE { $pre_id:tt , $pre_ty:ty , $pre_ex:expr } )* $( PARAM { $param:ident , $param_from:expr , $param_to:expr , $param_instancer:expr } )* @@ -653,9 +653,9 @@ macro_rules! benchmark_backend { components: &[($crate::BenchmarkParameter, u32)], verify: bool ) -> Result Result<(), &'static str>>, &'static str> { - $( - let $common = $common_from; - )* + // $( + // let $common = $common_from; + // )* $( // Prepare instance let $param = components.iter() diff --git a/frame/benchmarking/src/tests.rs b/frame/benchmarking/src/tests.rs index f86abebbb9287..89e773f259550 100644 --- a/frame/benchmarking/src/tests.rs +++ b/frame/benchmarking/src/tests.rs @@ -112,12 +112,12 @@ benchmarks!{ where_clause { where ::OtherEvent: Into<::Event> } _ { - // Define a common range for `b`. - let b in 1 .. 1000 => (); + // // // Define a common range for `b`. + } set_value { - let b in ...; + let b in 1 .. 1000; let caller = account::("caller", 0, 0); }: _ (RawOrigin::Signed(caller), b.into()) verify { @@ -125,7 +125,7 @@ benchmarks!{ } other_name { - let b in ...; + let b in 1 .. 1000; }: dummy (RawOrigin::None, b.into()) sort_vector { @@ -141,7 +141,7 @@ benchmarks!{ } bad_origin { - let b in ...; + let b in 1 .. 1000; let caller = account::("caller", 0, 0); }: dummy (RawOrigin::Signed(caller), b.into()) From fcb2c7c79729db7ccdf166585f254f95ac532cae Mon Sep 17 00:00:00 2001 From: Stanly Johnson Date: Fri, 25 Dec 2020 08:36:40 +0530 Subject: [PATCH 02/14] hack to pass tests --- frame/benchmarking/src/lib.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/frame/benchmarking/src/lib.rs b/frame/benchmarking/src/lib.rs index 08556e938ffca..c5944b4141138 100644 --- a/frame/benchmarking/src/lib.rs +++ b/frame/benchmarking/src/lib.rs @@ -200,17 +200,17 @@ macro_rules! benchmarks { macro_rules! benchmarks_instance { ( $( where_clause { where $( $where_ty:ty: $where_bound:path ),* $(,)? } )? - _ { - $( - let $common:ident in $common_from:tt .. $common_to:expr => $common_instancer:expr; - )* - } - $( $rest:tt )* + //_ { + // $( + // let $common:ident in $common_from:tt .. $common_to:expr => $common_instancer:expr; + // )* + //} + $( $rest:tt )? ) => { $crate::benchmarks_iter!( { I } { $( $( $where_ty: $where_bound ),* )? } - { $( { $common , $common_from , $common_to , $common_instancer } )* } + //{ $( { $common , $common_from , $common_to , $common_instancer } )* } ( ) ( ) $( $rest )* From 351876e1433f188949545a2df01643c8135f8f98 Mon Sep 17 00:00:00 2001 From: Stanly Johnson Date: Fri, 25 Dec 2020 08:52:37 +0530 Subject: [PATCH 03/14] another hack --- frame/benchmarking/src/lib.rs | 7 ++++--- frame/benchmarking/src/tests.rs | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/frame/benchmarking/src/lib.rs b/frame/benchmarking/src/lib.rs index c5944b4141138..45217bd308ee4 100644 --- a/frame/benchmarking/src/lib.rs +++ b/frame/benchmarking/src/lib.rs @@ -177,11 +177,12 @@ pub use sp_storage::TrackedStorageKey; macro_rules! benchmarks { ( $( where_clause { where $( $where_ty:ty: $where_bound:path ),* $(,)? } )? - _ { + , + //_ { // // // $( // // // let $common:ident in $common_from:tt .. $common_to:expr => $common_instancer:expr; // // // )* - } + //} $( $rest:tt )* ) => { $crate::benchmarks_iter!( @@ -205,7 +206,7 @@ macro_rules! benchmarks_instance { // let $common:ident in $common_from:tt .. $common_to:expr => $common_instancer:expr; // )* //} - $( $rest:tt )? + $( $rest:tt )* ) => { $crate::benchmarks_iter!( { I } diff --git a/frame/benchmarking/src/tests.rs b/frame/benchmarking/src/tests.rs index 89e773f259550..24cc44062631d 100644 --- a/frame/benchmarking/src/tests.rs +++ b/frame/benchmarking/src/tests.rs @@ -110,11 +110,12 @@ fn new_test_ext() -> sp_io::TestExternalities { benchmarks!{ where_clause { where ::OtherEvent: Into<::Event> } + , - _ { + //_ { // // // Define a common range for `b`. - } + //} set_value { let b in 1 .. 1000; From f842d5667867f25eb8d455231a032a1c0ed712e9 Mon Sep 17 00:00:00 2001 From: Stanly Johnson Date: Fri, 1 Jan 2021 15:37:13 +0530 Subject: [PATCH 04/14] remove all commented code --- frame/benchmarking/src/lib.rs | 60 ----------------------------------- 1 file changed, 60 deletions(-) diff --git a/frame/benchmarking/src/lib.rs b/frame/benchmarking/src/lib.rs index 45217bd308ee4..e297afdf16547 100644 --- a/frame/benchmarking/src/lib.rs +++ b/frame/benchmarking/src/lib.rs @@ -178,17 +178,11 @@ macro_rules! benchmarks { ( $( where_clause { where $( $where_ty:ty: $where_bound:path ),* $(,)? } )? , - //_ { - // // // $( - // // // let $common:ident in $common_from:tt .. $common_to:expr => $common_instancer:expr; - // // // )* - //} $( $rest:tt )* ) => { $crate::benchmarks_iter!( { } { $( $( $where_ty: $where_bound ),* )? } - //{ $( { $common , $common_from , $common_to , $common_instancer } )* } ( ) ( ) $( $rest )* @@ -201,17 +195,11 @@ macro_rules! benchmarks { macro_rules! benchmarks_instance { ( $( where_clause { where $( $where_ty:ty: $where_bound:path ),* $(,)? } )? - //_ { - // $( - // let $common:ident in $common_from:tt .. $common_to:expr => $common_instancer:expr; - // )* - //} $( $rest:tt )* ) => { $crate::benchmarks_iter!( { I } { $( $( $where_ty: $where_bound ),* )? } - //{ $( { $common , $common_from , $common_to , $common_instancer } )* } ( ) ( ) $( $rest )* @@ -226,7 +214,6 @@ macro_rules! benchmarks_iter { ( { $( $instance:ident )? } { $( $where_clause:tt )* } - //{ $( $common:tt )* } ( $( $names:tt )* ) ( $( $names_extra:tt )* ) #[extra] @@ -236,7 +223,6 @@ macro_rules! benchmarks_iter { $crate::benchmarks_iter! { { $( $instance)? } { $( $where_clause )* } - //{ $( $common )* } ( $( $names )* ) ( $( $names_extra )* $name ) $name @@ -247,7 +233,6 @@ macro_rules! benchmarks_iter { ( { $( $instance:ident )? } { $( $where_clause:tt )* } - //{ $( $common:tt )* } ( $( $names:tt )* ) // This contains $( $( { $instance } )? $name:ident )* ( $( $names_extra:tt )* ) $name:ident { $( $code:tt )* }: _ ( $origin:expr $( , $arg:expr )* ) @@ -257,7 +242,6 @@ macro_rules! benchmarks_iter { $crate::benchmarks_iter! { { $( $instance)? } { $( $where_clause )* } - //{ $( $common )* } ( $( $names )* ) ( $( $names_extra )* ) $name { $( $code )* }: $name ( $origin $( , $arg )* ) @@ -269,7 +253,6 @@ macro_rules! benchmarks_iter { ( { $( $instance:ident )? } { $( $where_clause:tt )* } - //{ $( $common:tt )* } ( $( $names:tt )* ) ( $( $names_extra:tt )* ) $name:ident { $( $code:tt )* }: $dispatch:ident ( $origin:expr $( , $arg:expr )* ) @@ -279,7 +262,6 @@ macro_rules! benchmarks_iter { $crate::benchmarks_iter! { { $( $instance)? } { $( $where_clause )* } - //{ $( $common )* } ( $( $names )* ) ( $( $names_extra )* ) $name { $( $code )* }: { @@ -297,7 +279,6 @@ macro_rules! benchmarks_iter { ( { $( $instance:ident )? } { $( $where_clause:tt )* } - //{ $( $common:tt )* } ( $( $names:tt )* ) ( $( $names_extra:tt )* ) $name:ident { $( $code:tt )* }: $eval:block @@ -308,7 +289,6 @@ macro_rules! benchmarks_iter { { $( $instance)? } $name { $( $where_clause )* } - //{ $( $common )* } { } { $eval } { $( $code )* } @@ -325,7 +305,6 @@ macro_rules! benchmarks_iter { $crate::benchmarks_iter!( { $( $instance)? } { $( $where_clause )* } - //{ $( $common )* } ( $( $names )* { $( $instance )? } $name ) ( $( $names_extra )* ) $( $rest )* @@ -335,7 +314,6 @@ macro_rules! benchmarks_iter { ( { $( $instance:ident )? } { $( $where_clause:tt )* } - //{ $( $common:tt )* } ( $( $names:tt )* ) ( $( $names_extra:tt )* ) ) => { @@ -355,7 +333,6 @@ macro_rules! benchmarks_iter { ( { $( $instance:ident )? } { $( $where_clause:tt )* } - //{ $( $common:tt )* } ( $( $names:tt )* ) ( $( $names_extra:tt )* ) $name:ident { $( $code:tt )* }: _ ( $origin:expr $( , $arg:expr )* ) @@ -364,7 +341,6 @@ macro_rules! benchmarks_iter { $crate::benchmarks_iter! { { $( $instance)? } { $( $where_clause )* } - //{ $( $common )* } ( $( $names )* ) ( $( $names_extra )* ) $name { $( $code )* }: _ ( $origin $( , $arg )* ) @@ -376,7 +352,6 @@ macro_rules! benchmarks_iter { ( { $( $instance:ident )? } { $( $where_clause:tt )* } - //{ $( $common:tt )* } ( $( $names:tt )* ) ( $( $names_extra:tt )* ) $name:ident { $( $code:tt )* }: $dispatch:ident ( $origin:expr $( , $arg:expr )* ) @@ -385,7 +360,6 @@ macro_rules! benchmarks_iter { $crate::benchmarks_iter! { { $( $instance)? } { $( $where_clause )* } - //{ $( $common )* } ( $( $names )* ) ( $( $names_extra )* ) $name { $( $code )* }: $dispatch ( $origin $( , $arg )* ) @@ -397,7 +371,6 @@ macro_rules! benchmarks_iter { ( { $( $instance:ident )? } { $( $where_clause:tt )* } - //{ $( $common:tt )* } ( $( $names:tt )* ) ( $( $names_extra:tt )* ) $name:ident { $( $code:tt )* }: $eval:block @@ -406,7 +379,6 @@ macro_rules! benchmarks_iter { $crate::benchmarks_iter!( { $( $instance)? } { $( $where_clause )* } - //{ $( $common )* } ( $( $names )* ) ( $( $names_extra )* ) $name { $( $code )* }: $eval @@ -424,7 +396,6 @@ macro_rules! benchmark_backend { { $( $instance:ident )? } $name:ident { $( $where_clause:tt )* } - //{ $( $common:tt )* } { $( PRE { $( $pre_parsed:tt )* } )* } { $eval:block } { @@ -437,7 +408,6 @@ macro_rules! benchmark_backend { { $( $instance)? } $name { $( $where_clause )* } - //{ $( $common )* } { $( PRE { $( $pre_parsed )* } )* PRE { $pre_id , $pre_ty , $pre_ex } @@ -451,7 +421,6 @@ macro_rules! benchmark_backend { { $( $instance:ident )? } $name:ident { $( $where_clause:tt )* } - //{ $( $common:tt )* } { $( $parsed:tt )* } { $eval:block } { @@ -464,7 +433,6 @@ macro_rules! benchmark_backend { { $( $instance)? } $name { $( $where_clause )* } - //{ $( $common )* } { $( $parsed )* PARAM { $param , $param_from , $param_to , $param_instancer } @@ -479,7 +447,6 @@ macro_rules! benchmark_backend { { $( $instance:ident )? } $name:ident { $( $where_clause:tt )* } - //{ $( { $common:ident , $common_from:tt , $common_to:expr , $common_instancer:expr } )* } { $( $parsed:tt )* } { $eval:block } { @@ -492,16 +459,8 @@ macro_rules! benchmark_backend { { $( $instance)? } $name { $( $where_clause )* } - //{ $( { $common , $common_from , $common_to , $common_instancer } )* } { $( $parsed )* } { $eval } - // { - // let $param - // in ({ $( let $common = $common_from; )* $param }) - // .. ({ $( let $common = $common_to; )* $param }) - // => ({ $( let $common = || -> Result<(), &'static str> { $common_instancer ; Ok(()) }; )* $param()? }); - // $( $rest )* - // } $postcode } }; @@ -510,7 +469,6 @@ macro_rules! benchmark_backend { { $( $instance:ident )? } $name:ident { $( $where_clause:tt )* } - //{ $( { $common:ident , $common_from:tt , $common_to:expr , $common_instancer:expr } )* } { $( $parsed:tt )* } { $eval:block } { @@ -523,16 +481,8 @@ macro_rules! benchmark_backend { { $( $instance)? } $name { $( $where_clause )* } - //{ $( { $common , $common_from , $common_to , $common_instancer } )* } { $( $parsed )* } { $eval } - // { - // let $param - // in ({ $( let $common = $common_from; )* $param }) - // .. ({ $( let $common = $common_to; )* $param }) - // => $param_instancer ; - // $( $rest )* - // } $postcode } }; @@ -541,7 +491,6 @@ macro_rules! benchmark_backend { { $( $instance:ident )? } $name:ident { $( $where_clause:tt )* } - //{ $( $common:tt )* } { $( $parsed:tt )* } { $eval:block } { @@ -554,7 +503,6 @@ macro_rules! benchmark_backend { { $( $instance)? } $name { $( $where_clause )* } - //{ $( $common )* } { $( $parsed )* } { $eval } { @@ -569,7 +517,6 @@ macro_rules! benchmark_backend { { $( $instance:ident )? } $name:ident { $( $where_clause:tt )* } - //{ $( $common:tt )* } { $( $parsed:tt )* } { $eval:block } { @@ -582,7 +529,6 @@ macro_rules! benchmark_backend { { $( $instance)? } $name { $( $where_clause )* } - //{ $( $common )* } { $( $parsed )* } { $eval } { @@ -597,7 +543,6 @@ macro_rules! benchmark_backend { { $( $instance:ident )? } $name:ident { $( $where_clause:tt )* } - //{ $( $common:tt )* } { $( $parsed:tt )* } { $eval:block } { @@ -610,7 +555,6 @@ macro_rules! benchmark_backend { { $( $instance)? } $name { $( $where_clause )* } - //{ $( $common )* } { $( $parsed )* } { $eval } { @@ -625,7 +569,6 @@ macro_rules! benchmark_backend { { $( $instance:ident )? } $name:ident { $( $where_clause:tt )* } - //{ $( { $common:ident , $common_from:tt , $common_to:expr , $common_instancer:expr } )* } { $( PRE { $pre_id:tt , $pre_ty:ty , $pre_ex:expr } )* $( PARAM { $param:ident , $param_from:expr , $param_to:expr , $param_instancer:expr } )* @@ -654,9 +597,6 @@ macro_rules! benchmark_backend { components: &[($crate::BenchmarkParameter, u32)], verify: bool ) -> Result Result<(), &'static str>>, &'static str> { - // $( - // let $common = $common_from; - // )* $( // Prepare instance let $param = components.iter() From aaff3ef18682ba4177883402f795498cff9669a5 Mon Sep 17 00:00:00 2001 From: Stanly Johnson Date: Fri, 1 Jan 2021 15:59:41 +0530 Subject: [PATCH 05/14] fix the easy tests --- frame/benchmarking/src/tests.rs | 6 ------ frame/collective/src/benchmarking.rs | 3 +-- frame/treasury/src/benchmarking.rs | 3 +-- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/frame/benchmarking/src/tests.rs b/frame/benchmarking/src/tests.rs index 24cc44062631d..117ff878c93b4 100644 --- a/frame/benchmarking/src/tests.rs +++ b/frame/benchmarking/src/tests.rs @@ -111,12 +111,6 @@ fn new_test_ext() -> sp_io::TestExternalities { benchmarks!{ where_clause { where ::OtherEvent: Into<::Event> } , - - //_ { - // // // Define a common range for `b`. - - //} - set_value { let b in 1 .. 1000; let caller = account::("caller", 0, 0); diff --git a/frame/collective/src/benchmarking.rs b/frame/collective/src/benchmarking.rs index 551d6c7856cda..f5ed5d704e640 100644 --- a/frame/collective/src/benchmarking.rs +++ b/frame/collective/src/benchmarking.rs @@ -42,8 +42,7 @@ fn assert_last_event, I: Instance>(generic_event: >: } benchmarks_instance! { - _{ } - + set_members { let m in 1 .. T::MaxMembers::get(); let n in 1 .. T::MaxMembers::get(); diff --git a/frame/treasury/src/benchmarking.rs b/frame/treasury/src/benchmarking.rs index 16ed1b01ae0d0..c919dbf081bc5 100644 --- a/frame/treasury/src/benchmarking.rs +++ b/frame/treasury/src/benchmarking.rs @@ -66,8 +66,7 @@ fn setup_pod_account, I: Instance>() { } benchmarks_instance! { - _ { } - + propose_spend { let (caller, value, beneficiary_lookup) = setup_proposal::(SEED); // Whitelist caller account from further DB operations. From 399b9bab708fedc5f30177b1c64934c0c3bf853a Mon Sep 17 00:00:00 2001 From: Stanly Johnson Date: Mon, 4 Jan 2021 23:42:00 +0530 Subject: [PATCH 06/14] temp hack --- frame/staking/src/benchmarking.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frame/staking/src/benchmarking.rs b/frame/staking/src/benchmarking.rs index d336bfd1ddda5..71485e0520290 100644 --- a/frame/staking/src/benchmarking.rs +++ b/frame/staking/src/benchmarking.rs @@ -113,8 +113,7 @@ pub fn create_validator_with_nominators( const USER_SEED: u32 = 999666; benchmarks! { - _{} - + , bond { let stash = create_funded_user::("stash", USER_SEED, 100); let controller = create_funded_user::("controller", USER_SEED, 100); From 55e03fba6cc723c6f46f66860b879c9cc86138df Mon Sep 17 00:00:00 2001 From: Stanly Johnson Date: Tue, 5 Jan 2021 00:01:21 +0530 Subject: [PATCH 07/14] follow through comma hack until better solution --- frame/assets/src/benchmarking.rs | 2 +- frame/babe/src/benchmarking.rs | 2 +- frame/balances/src/benchmarking.rs | 2 +- frame/bounties/src/benchmarking.rs | 2 +- frame/contracts/src/benchmarking/mod.rs | 2 +- frame/democracy/src/benchmarking.rs | 2 +- frame/elections-phragmen/src/benchmarking.rs | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/frame/assets/src/benchmarking.rs b/frame/assets/src/benchmarking.rs index cecb2ccae58b4..d22891ae66122 100644 --- a/frame/assets/src/benchmarking.rs +++ b/frame/assets/src/benchmarking.rs @@ -74,7 +74,7 @@ fn assert_last_event(generic_event: ::Event) { } benchmarks! { - _ { } + , create { let caller: T::AccountId = whitelisted_caller(); diff --git a/frame/babe/src/benchmarking.rs b/frame/babe/src/benchmarking.rs index 8ee4a5913c885..112f32c530c35 100644 --- a/frame/babe/src/benchmarking.rs +++ b/frame/babe/src/benchmarking.rs @@ -23,7 +23,7 @@ use frame_benchmarking::benchmarks; type Header = sp_runtime::generic::Header; benchmarks! { - _ { } + , check_equivocation_proof { let x in 0 .. 1; diff --git a/frame/balances/src/benchmarking.rs b/frame/balances/src/benchmarking.rs index 078d74006ba2f..1764c82c61657 100644 --- a/frame/balances/src/benchmarking.rs +++ b/frame/balances/src/benchmarking.rs @@ -33,7 +33,7 @@ const ED_MULTIPLIER: u32 = 10; benchmarks! { - _ { } + , // Benchmark `transfer` extrinsic with the worst possible conditions: // * Transfer will kill the sender account. diff --git a/frame/bounties/src/benchmarking.rs b/frame/bounties/src/benchmarking.rs index 5a323ff0aafcc..12c7ca18f46e1 100644 --- a/frame/bounties/src/benchmarking.rs +++ b/frame/bounties/src/benchmarking.rs @@ -94,7 +94,7 @@ fn assert_last_event(generic_event: ::Event) { const MAX_BYTES: u32 = 16384; benchmarks! { - _ { } + , propose_bounty { let d in 0 .. MAX_BYTES; diff --git a/frame/contracts/src/benchmarking/mod.rs b/frame/contracts/src/benchmarking/mod.rs index 4bdd279eb8b2c..5eab5c34d3d9b 100644 --- a/frame/contracts/src/benchmarking/mod.rs +++ b/frame/contracts/src/benchmarking/mod.rs @@ -265,7 +265,7 @@ benchmarks! { where_clause { where T::AccountId: UncheckedFrom, T::AccountId: AsRef<[u8]>, - } + }, _ { } diff --git a/frame/democracy/src/benchmarking.rs b/frame/democracy/src/benchmarking.rs index 542bfaa79db11..e0f16030a08f1 100644 --- a/frame/democracy/src/benchmarking.rs +++ b/frame/democracy/src/benchmarking.rs @@ -97,7 +97,7 @@ fn account_vote(b: BalanceOf) -> AccountVote> { } benchmarks! { - _ { } + , propose { let p = T::MaxProposals::get(); diff --git a/frame/elections-phragmen/src/benchmarking.rs b/frame/elections-phragmen/src/benchmarking.rs index eaa5bbe9ed4fb..a75fd794bc190 100644 --- a/frame/elections-phragmen/src/benchmarking.rs +++ b/frame/elections-phragmen/src/benchmarking.rs @@ -166,7 +166,7 @@ fn clean() { } benchmarks! { - _ {} + , // -- Signed ones vote { From d498023e260d4e4505af741b649c93f715dc7a49 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 4 Jan 2021 20:22:06 -0400 Subject: [PATCH 08/14] patch macro --- frame/assets/src/benchmarking.rs | 2 -- frame/babe/src/benchmarking.rs | 2 -- frame/balances/src/benchmarking.rs | 2 -- frame/benchmarking/src/lib.rs | 24 +++++++++++++++---- frame/benchmarking/src/tests.rs | 2 +- frame/bounties/src/benchmarking.rs | 2 -- frame/democracy/src/benchmarking.rs | 2 -- frame/elections-phragmen/src/benchmarking.rs | 2 -- frame/grandpa/src/benchmarking.rs | 2 -- frame/im-online/src/benchmarking.rs | 2 -- frame/indices/src/benchmarking.rs | 2 -- .../merkle-mountain-range/src/benchmarking.rs | 2 -- frame/multisig/src/benchmarking.rs | 2 -- frame/offences/benchmarking/src/lib.rs | 2 -- frame/scheduler/src/benchmarking.rs | 2 -- frame/session/benchmarking/src/lib.rs | 2 -- frame/staking/src/benchmarking.rs | 1 - frame/system/benchmarking/src/lib.rs | 2 -- frame/timestamp/src/benchmarking.rs | 2 -- frame/tips/src/benchmarking.rs | 2 -- frame/utility/src/benchmarking.rs | 2 -- frame/vesting/src/benchmarking.rs | 2 -- 22 files changed, 20 insertions(+), 45 deletions(-) diff --git a/frame/assets/src/benchmarking.rs b/frame/assets/src/benchmarking.rs index d22891ae66122..7e9d8b55c432e 100644 --- a/frame/assets/src/benchmarking.rs +++ b/frame/assets/src/benchmarking.rs @@ -74,8 +74,6 @@ fn assert_last_event(generic_event: ::Event) { } benchmarks! { - , - create { let caller: T::AccountId = whitelisted_caller(); let caller_lookup = T::Lookup::unlookup(caller.clone()); diff --git a/frame/babe/src/benchmarking.rs b/frame/babe/src/benchmarking.rs index 112f32c530c35..5ef5f4780b985 100644 --- a/frame/babe/src/benchmarking.rs +++ b/frame/babe/src/benchmarking.rs @@ -23,8 +23,6 @@ use frame_benchmarking::benchmarks; type Header = sp_runtime::generic::Header; benchmarks! { - , - check_equivocation_proof { let x in 0 .. 1; diff --git a/frame/balances/src/benchmarking.rs b/frame/balances/src/benchmarking.rs index 1764c82c61657..d26c0f5249e25 100644 --- a/frame/balances/src/benchmarking.rs +++ b/frame/balances/src/benchmarking.rs @@ -33,8 +33,6 @@ const ED_MULTIPLIER: u32 = 10; benchmarks! { - , - // Benchmark `transfer` extrinsic with the worst possible conditions: // * Transfer will kill the sender account. // * Transfer will create the recipient account. diff --git a/frame/benchmarking/src/lib.rs b/frame/benchmarking/src/lib.rs index e297afdf16547..db8c7ffd4b783 100644 --- a/frame/benchmarking/src/lib.rs +++ b/frame/benchmarking/src/lib.rs @@ -176,13 +176,11 @@ pub use sp_storage::TrackedStorageKey; #[macro_export] macro_rules! benchmarks { ( - $( where_clause { where $( $where_ty:ty: $where_bound:path ),* $(,)? } )? - , $( $rest:tt )* ) => { $crate::benchmarks_iter!( { } - { $( $( $where_ty: $where_bound ),* )? } + { } ( ) ( ) $( $rest )* @@ -194,12 +192,11 @@ macro_rules! benchmarks { #[macro_export] macro_rules! benchmarks_instance { ( - $( where_clause { where $( $where_ty:ty: $where_bound:path ),* $(,)? } )? $( $rest:tt )* ) => { $crate::benchmarks_iter!( { I } - { $( $( $where_ty: $where_bound ),* )? } + { } ( ) ( ) $( $rest )* @@ -210,6 +207,23 @@ macro_rules! benchmarks_instance { #[macro_export] #[doc(hidden)] macro_rules! benchmarks_iter { + // detect and extract where clause: + ( + { $( $instance:ident )? } + { $( $where_clause:tt )* } + ( $( $names:tt )* ) + ( $( $names_extra:tt )* ) + where_clause { where $( $where_ty:ty: $where_bound:path ),* $(,)? } + $( $rest:tt )* + ) => { + $crate::benchmarks_iter! { + { $( $instance)? } + { $( $where_ty: $where_bound ),* } + ( $( $names )* ) + ( $( $names_extra )* ) + $( $rest )* + } + }; // detect and extract extra tag: ( { $( $instance:ident )? } diff --git a/frame/benchmarking/src/tests.rs b/frame/benchmarking/src/tests.rs index 117ff878c93b4..c1a41f3ce59f8 100644 --- a/frame/benchmarking/src/tests.rs +++ b/frame/benchmarking/src/tests.rs @@ -110,7 +110,7 @@ fn new_test_ext() -> sp_io::TestExternalities { benchmarks!{ where_clause { where ::OtherEvent: Into<::Event> } - , + set_value { let b in 1 .. 1000; let caller = account::("caller", 0, 0); diff --git a/frame/bounties/src/benchmarking.rs b/frame/bounties/src/benchmarking.rs index 12c7ca18f46e1..7da2163abfddd 100644 --- a/frame/bounties/src/benchmarking.rs +++ b/frame/bounties/src/benchmarking.rs @@ -94,8 +94,6 @@ fn assert_last_event(generic_event: ::Event) { const MAX_BYTES: u32 = 16384; benchmarks! { - , - propose_bounty { let d in 0 .. MAX_BYTES; diff --git a/frame/democracy/src/benchmarking.rs b/frame/democracy/src/benchmarking.rs index e0f16030a08f1..4b36bec3ee7d0 100644 --- a/frame/democracy/src/benchmarking.rs +++ b/frame/democracy/src/benchmarking.rs @@ -97,8 +97,6 @@ fn account_vote(b: BalanceOf) -> AccountVote> { } benchmarks! { - , - propose { let p = T::MaxProposals::get(); diff --git a/frame/elections-phragmen/src/benchmarking.rs b/frame/elections-phragmen/src/benchmarking.rs index a75fd794bc190..75da730ecf565 100644 --- a/frame/elections-phragmen/src/benchmarking.rs +++ b/frame/elections-phragmen/src/benchmarking.rs @@ -166,8 +166,6 @@ fn clean() { } benchmarks! { - , - // -- Signed ones vote { let v in 1 .. (MAXIMUM_VOTE as u32); diff --git a/frame/grandpa/src/benchmarking.rs b/frame/grandpa/src/benchmarking.rs index bac2c24584464..d6acfd32e2534 100644 --- a/frame/grandpa/src/benchmarking.rs +++ b/frame/grandpa/src/benchmarking.rs @@ -25,8 +25,6 @@ use frame_system::RawOrigin; use sp_core::H256; benchmarks! { - _ { } - check_equivocation_proof { let x in 0 .. 1; diff --git a/frame/im-online/src/benchmarking.rs b/frame/im-online/src/benchmarking.rs index 452a9f26ed7d0..60270b7431e89 100644 --- a/frame/im-online/src/benchmarking.rs +++ b/frame/im-online/src/benchmarking.rs @@ -63,8 +63,6 @@ pub fn create_heartbeat(k: u32, e: u32) -> } benchmarks! { - _{ } - #[extra] heartbeat { let k in 1 .. MAX_KEYS; diff --git a/frame/indices/src/benchmarking.rs b/frame/indices/src/benchmarking.rs index 382bf07f1136e..07620b24fc54d 100644 --- a/frame/indices/src/benchmarking.rs +++ b/frame/indices/src/benchmarking.rs @@ -29,8 +29,6 @@ use crate::Module as Indices; const SEED: u32 = 0; benchmarks! { - _ { } - claim { let account_index = T::AccountIndex::from(SEED); let caller: T::AccountId = whitelisted_caller(); diff --git a/frame/merkle-mountain-range/src/benchmarking.rs b/frame/merkle-mountain-range/src/benchmarking.rs index af634e18821fc..24fa5083dadf2 100644 --- a/frame/merkle-mountain-range/src/benchmarking.rs +++ b/frame/merkle-mountain-range/src/benchmarking.rs @@ -25,8 +25,6 @@ use frame_benchmarking::benchmarks; use sp_std::prelude::*; benchmarks! { - _ { } - on_initialize { let x in 1 .. 1_000; diff --git a/frame/multisig/src/benchmarking.rs b/frame/multisig/src/benchmarking.rs index 0b549b3d94717..16f287c0ccb82 100644 --- a/frame/multisig/src/benchmarking.rs +++ b/frame/multisig/src/benchmarking.rs @@ -48,8 +48,6 @@ fn setup_multi(s: u32, z: u32) } benchmarks! { - _ { } - as_multi_threshold_1 { // Transaction Length let z in 0 .. 10_000; diff --git a/frame/offences/benchmarking/src/lib.rs b/frame/offences/benchmarking/src/lib.rs index 1d133c1b613bc..840bcc7e54d87 100644 --- a/frame/offences/benchmarking/src/lib.rs +++ b/frame/offences/benchmarking/src/lib.rs @@ -203,8 +203,6 @@ fn check_events::Event>>(expec } benchmarks! { - _ { } - report_offence_im_online { let r in 1 .. MAX_REPORTERS; // we skip 1 offender, because in such case there is no slashing diff --git a/frame/scheduler/src/benchmarking.rs b/frame/scheduler/src/benchmarking.rs index 6a67efc9d2dca..b4a52285d86d3 100644 --- a/frame/scheduler/src/benchmarking.rs +++ b/frame/scheduler/src/benchmarking.rs @@ -52,8 +52,6 @@ fn fill_schedule (when: T::BlockNumber, n: u32) -> Result<(), &'stati } benchmarks! { - _ { } - schedule { let s in 0 .. T::MaxScheduledPerBlock::get(); let when = BLOCK_NUMBER.into(); diff --git a/frame/session/benchmarking/src/lib.rs b/frame/session/benchmarking/src/lib.rs index bd85b97c0d33e..e2872ee3a1a2e 100644 --- a/frame/session/benchmarking/src/lib.rs +++ b/frame/session/benchmarking/src/lib.rs @@ -51,8 +51,6 @@ impl OnInitialize for Module { } benchmarks! { - _ { } - set_keys { let n = MAX_NOMINATIONS as u32; let (v_stash, _) = create_validator_with_nominators::( diff --git a/frame/staking/src/benchmarking.rs b/frame/staking/src/benchmarking.rs index 71485e0520290..b345c93089c1f 100644 --- a/frame/staking/src/benchmarking.rs +++ b/frame/staking/src/benchmarking.rs @@ -113,7 +113,6 @@ pub fn create_validator_with_nominators( const USER_SEED: u32 = 999666; benchmarks! { - , bond { let stash = create_funded_user::("stash", USER_SEED, 100); let controller = create_funded_user::("controller", USER_SEED, 100); diff --git a/frame/system/benchmarking/src/lib.rs b/frame/system/benchmarking/src/lib.rs index 080b1cd80f297..d3b2e58502d98 100644 --- a/frame/system/benchmarking/src/lib.rs +++ b/frame/system/benchmarking/src/lib.rs @@ -38,8 +38,6 @@ pub struct Module(System); pub trait Config: frame_system::Config {} benchmarks! { - _ { } - remark { let b in 0 .. *T::BlockLength::get().max.get(DispatchClass::Normal) as u32; let remark_message = vec![1; b as usize]; diff --git a/frame/timestamp/src/benchmarking.rs b/frame/timestamp/src/benchmarking.rs index a0700179a9336..468499134e622 100644 --- a/frame/timestamp/src/benchmarking.rs +++ b/frame/timestamp/src/benchmarking.rs @@ -30,8 +30,6 @@ use crate::Module as Timestamp; const MAX_TIME: u32 = 100; benchmarks! { - _ { } - set { let t = MAX_TIME; // Ignore write to `DidUpdate` since it transient. diff --git a/frame/tips/src/benchmarking.rs b/frame/tips/src/benchmarking.rs index 71f9002b9bf11..022b736fc15d4 100644 --- a/frame/tips/src/benchmarking.rs +++ b/frame/tips/src/benchmarking.rs @@ -89,8 +89,6 @@ const MAX_BYTES: u32 = 16384; const MAX_TIPPERS: u32 = 100; benchmarks! { - _ { } - report_awesome { let r in 0 .. MAX_BYTES; let (caller, reason, awesome_person) = setup_awesome::(r); diff --git a/frame/utility/src/benchmarking.rs b/frame/utility/src/benchmarking.rs index 501e1b293bcc1..1b23656f7ae4c 100644 --- a/frame/utility/src/benchmarking.rs +++ b/frame/utility/src/benchmarking.rs @@ -34,8 +34,6 @@ fn assert_last_event(generic_event: ::Event) { } benchmarks! { - _ { } - batch { let c in 0 .. 1000; let mut calls: Vec<::Call> = Vec::new(); diff --git a/frame/vesting/src/benchmarking.rs b/frame/vesting/src/benchmarking.rs index 0cb030668d050..31c2bd97209b0 100644 --- a/frame/vesting/src/benchmarking.rs +++ b/frame/vesting/src/benchmarking.rs @@ -58,8 +58,6 @@ fn add_vesting_schedule(who: &T::AccountId) -> Result<(), &'static st } benchmarks! { - _ { } - vest_locked { let l in 0 .. MaxLocksOf::::get(); From 47fcd6b742d18f6747974819591f02376173c9f4 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 4 Jan 2021 20:25:33 -0400 Subject: [PATCH 09/14] missed one --- frame/contracts/src/benchmarking/mod.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/frame/contracts/src/benchmarking/mod.rs b/frame/contracts/src/benchmarking/mod.rs index 5eab5c34d3d9b..1d71743b86e1d 100644 --- a/frame/contracts/src/benchmarking/mod.rs +++ b/frame/contracts/src/benchmarking/mod.rs @@ -265,9 +265,6 @@ benchmarks! { where_clause { where T::AccountId: UncheckedFrom, T::AccountId: AsRef<[u8]>, - }, - - _ { } // This extrinsic is pretty much constant as it is only a simple setter. From dd2ff39b0a3d843516ab1518a15511c7bcde2c0c Mon Sep 17 00:00:00 2001 From: Stanly Johnson Date: Tue, 5 Jan 2021 10:20:46 +0530 Subject: [PATCH 10/14] update benchmarks --- frame/contracts/src/benchmarking/mod.rs | 3 - frame/example/src/lib.rs | 9 +-- frame/identity/src/benchmarking.rs | 87 +++++++++++++++---------- frame/proxy/src/benchmarking.rs | 22 +++---- 4 files changed, 62 insertions(+), 59 deletions(-) diff --git a/frame/contracts/src/benchmarking/mod.rs b/frame/contracts/src/benchmarking/mod.rs index d08f0ab5e65ec..9fa365116c7a0 100644 --- a/frame/contracts/src/benchmarking/mod.rs +++ b/frame/contracts/src/benchmarking/mod.rs @@ -282,9 +282,6 @@ benchmarks! { T::AccountId: AsRef<[u8]>, } - _ { - } - // The base weight without any actual work performed apart from the setup costs. on_initialize {}: { Storage::::process_deletion_queue_batch(Weight::max_value()) diff --git a/frame/example/src/lib.rs b/frame/example/src/lib.rs index 382d67263d1b0..05526d2c7a29e 100644 --- a/frame/example/src/lib.rs +++ b/frame/example/src/lib.rs @@ -655,20 +655,15 @@ mod benchmarking { use frame_system::RawOrigin; benchmarks!{ - _ { - // Define a common range for `b`. - let b in 1 .. 1000 => (); - } - // This will measure the execution time of `accumulate_dummy` for b in [1..1000] range. accumulate_dummy { - let b in ...; + let b in 1 .. 1000; let caller = account("caller", 0, 0); }: _ (RawOrigin::Signed(caller), b.into()) // This will measure the execution time of `set_dummy` for b in [1..1000] range. set_dummy { - let b in ...; + let b in 1 .. 1000; }: set_dummy (RawOrigin::Root, b.into()) // This will measure the execution time of `set_dummy` for b in [1..10] range. diff --git a/frame/identity/src/benchmarking.rs b/frame/identity/src/benchmarking.rs index dccef494a0e88..1a0ba284ce11e 100644 --- a/frame/identity/src/benchmarking.rs +++ b/frame/identity/src/benchmarking.rs @@ -107,25 +107,6 @@ fn create_identity_info(num_fields: u32) -> IdentityInfo { } benchmarks! { - // These are the common parameters along with their instancing. - _ { - let r in 1 .. T::MaxRegistrars::get() => add_registrars::(r)?; - // extra parameter for the set_subs bench for previous sub accounts - let p in 1 .. T::MaxSubAccounts::get() => (); - let s in 1 .. T::MaxSubAccounts::get() => { - // Give them s many sub accounts - let caller: T::AccountId = whitelisted_caller(); - let _ = add_sub_accounts::(&caller, s)?; - }; - let x in 1 .. T::MaxAdditionalFields::get() => { - // Create their main identity with x additional fields - let info = create_identity_info::(x); - let caller: T::AccountId = whitelisted_caller(); - let caller_origin = ::Origin::from(RawOrigin::Signed(caller)); - Identity::::set_identity(caller_origin, info)?; - }; - } - add_registrar { let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::(r)?; ensure!(Registrars::::get().len() as u32 == r, "Registrars not set up correctly."); @@ -135,10 +116,14 @@ benchmarks! { } set_identity { - let r in ...; - // This X doesn't affect the caller ID up front like with the others, so we don't use the - // standard preparation. - let x in _ .. _ => (); + let r in 1 .. T::MaxRegistrars::get() => add_registrars::(r)?; + let x in 1 .. T::MaxAdditionalFields::get() => { + // Create their main identity with x additional fields + let info = create_identity_info::(x); + let caller: T::AccountId = whitelisted_caller(); + let caller_origin = ::Origin::from(RawOrigin::Signed(caller)); + Identity::::set_identity(caller_origin, info)?; + }; let caller = { // The target user let caller: T::AccountId = whitelisted_caller(); @@ -204,9 +189,19 @@ benchmarks! { let caller_lookup = ::unlookup(caller.clone()); let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); - let r in ...; - let s in ...; - let x in ...; + let r in 1 .. T::MaxRegistrars::get() => add_registrars::(r)?; + let s in 1 .. T::MaxSubAccounts::get() => { + // Give them s many sub accounts + let caller: T::AccountId = whitelisted_caller(); + let _ = add_sub_accounts::(&caller, s)?; + }; + let x in 1 .. T::MaxAdditionalFields::get() => { + // Create their main identity with x additional fields + let info = create_identity_info::(x); + let caller: T::AccountId = whitelisted_caller(); + let caller_origin = ::Origin::from(RawOrigin::Signed(caller)); + Identity::::set_identity(caller_origin, info)?; + }; // User requests judgement from all the registrars, and they approve for i in 0..r { @@ -228,8 +223,14 @@ benchmarks! { let caller: T::AccountId = whitelisted_caller(); let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); - let r in ...; - let x in ...; + let r in 1 .. T::MaxRegistrars::get() => add_registrars::(r)?; + let x in 1 .. T::MaxAdditionalFields::get() => { + // Create their main identity with x additional fields + let info = create_identity_info::(x); + let caller: T::AccountId = whitelisted_caller(); + let caller_origin = ::Origin::from(RawOrigin::Signed(caller)); + Identity::::set_identity(caller_origin, info)?; + }; }: _(RawOrigin::Signed(caller.clone()), r - 1, 10u32.into()) verify { assert_last_event::(Event::::JudgementRequested(caller, r-1).into()); @@ -240,8 +241,14 @@ benchmarks! { let caller_origin = ::Origin::from(RawOrigin::Signed(caller.clone())); let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); - let r in ...; - let x in ...; + let r in 1 .. T::MaxRegistrars::get() => add_registrars::(r)?; + let x in 1 .. T::MaxAdditionalFields::get() => { + // Create their main identity with x additional fields + let info = create_identity_info::(x); + let caller: T::AccountId = whitelisted_caller(); + let caller_origin = ::Origin::from(RawOrigin::Signed(caller)); + Identity::::set_identity(caller_origin, info)?; + }; Identity::::request_judgement(caller_origin, r - 1, 10u32.into())?; }: _(RawOrigin::Signed(caller.clone()), r - 1) @@ -308,8 +315,7 @@ benchmarks! { let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::(r)?; - // For this x, it's the user identity that gts the fields, not the caller. - let x in _ .. _ => { + let x in 1 .. T::MaxAdditionalFields::get() => { let info = create_identity_info::(x); Identity::::set_identity(user_origin.clone(), info)?; }; @@ -322,10 +328,19 @@ benchmarks! { } kill_identity { - let r in ...; - // Setting up our own account below. - let s in _ .. _ => {}; - let x in _ .. _ => {}; + let r in 1 .. T::MaxRegistrars::get() => add_registrars::(r)?; + let s in 1 .. T::MaxSubAccounts::get() => { + // Give them s many sub accounts + let caller: T::AccountId = whitelisted_caller(); + let _ = add_sub_accounts::(&caller, s)?; + }; + let x in 1 .. T::MaxAdditionalFields::get() => { + // Create their main identity with x additional fields + let info = create_identity_info::(x); + let caller: T::AccountId = whitelisted_caller(); + let caller_origin = ::Origin::from(RawOrigin::Signed(caller)); + Identity::::set_identity(caller_origin, info)?; + }; let target: T::AccountId = account("target", 0, SEED); let target_origin: ::Origin = RawOrigin::Signed(target.clone()).into(); diff --git a/frame/proxy/src/benchmarking.rs b/frame/proxy/src/benchmarking.rs index b08b47123d919..29c2e475c64ff 100644 --- a/frame/proxy/src/benchmarking.rs +++ b/frame/proxy/src/benchmarking.rs @@ -80,12 +80,8 @@ fn add_announcements( } benchmarks! { - _ { - let p in 1 .. (T::MaxProxies::get() - 1).into() => add_proxies::(p, None)?; - } - proxy { - let p in ...; + let p in 1 .. (T::MaxProxies::get() - 1).into() => add_proxies::(p, None)?; // In this case the caller is the "target" proxy let caller: T::AccountId = account("target", p - 1, SEED); T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); @@ -99,7 +95,7 @@ benchmarks! { proxy_announced { let a in 0 .. T::MaxPending::get() - 1; - let p in ...; + let p in 1 .. (T::MaxProxies::get() - 1).into() => add_proxies::(p, None)?; // In this case the caller is the "target" proxy let caller: T::AccountId = account("anonymous", 0, SEED); let delegate: T::AccountId = account("target", p - 1, SEED); @@ -120,7 +116,7 @@ benchmarks! { remove_announcement { let a in 0 .. T::MaxPending::get() - 1; - let p in ...; + let p in 1 .. (T::MaxProxies::get() - 1).into() => add_proxies::(p, None)?; // In this case the caller is the "target" proxy let caller: T::AccountId = account("target", p - 1, SEED); T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); @@ -141,7 +137,7 @@ benchmarks! { reject_announcement { let a in 0 .. T::MaxPending::get() - 1; - let p in ...; + let p in 1 .. (T::MaxProxies::get() - 1).into() => add_proxies::(p, None)?; // In this case the caller is the "target" proxy let caller: T::AccountId = account("target", p - 1, SEED); T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); @@ -162,7 +158,7 @@ benchmarks! { announce { let a in 0 .. T::MaxPending::get() - 1; - let p in ...; + let p in 1 .. (T::MaxProxies::get() - 1).into() => add_proxies::(p, None)?; // In this case the caller is the "target" proxy let caller: T::AccountId = account("target", p - 1, SEED); T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); @@ -177,7 +173,7 @@ benchmarks! { } add_proxy { - let p in ...; + let p in 1 .. (T::MaxProxies::get() - 1).into() => add_proxies::(p, None)?; let caller: T::AccountId = whitelisted_caller(); }: _( RawOrigin::Signed(caller.clone()), @@ -191,7 +187,7 @@ benchmarks! { } remove_proxy { - let p in ...; + let p in 1 .. (T::MaxProxies::get() - 1).into() => add_proxies::(p, None)?; let caller: T::AccountId = whitelisted_caller(); }: _( RawOrigin::Signed(caller.clone()), @@ -205,7 +201,7 @@ benchmarks! { } remove_proxies { - let p in ...; + let p in 1 .. (T::MaxProxies::get() - 1).into() => add_proxies::(p, None)?; let caller: T::AccountId = whitelisted_caller(); }: _(RawOrigin::Signed(caller.clone())) verify { @@ -214,7 +210,7 @@ benchmarks! { } anonymous { - let p in ...; + let p in 1 .. (T::MaxProxies::get() - 1).into() => add_proxies::(p, None)?; let caller: T::AccountId = whitelisted_caller(); }: _( RawOrigin::Signed(caller.clone()), From 4933b49d99f054ba123b2ea6911bc78b7514031f Mon Sep 17 00:00:00 2001 From: Stanly Johnson Date: Tue, 5 Jan 2021 10:20:55 +0530 Subject: [PATCH 11/14] update docs --- frame/benchmarking/src/lib.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/frame/benchmarking/src/lib.rs b/frame/benchmarking/src/lib.rs index 399ff927530e0..8923ab6c7ff96 100644 --- a/frame/benchmarking/src/lib.rs +++ b/frame/benchmarking/src/lib.rs @@ -88,12 +88,6 @@ pub use sp_storage::TrackedStorageKey; /// benchmarks! { /// where_clause { where T::A: From } // Optional line to give additional bound on `T`. /// -/// // common parameter; just one for this example. -/// // will be `1`, `MAX_LENGTH` or any value inbetween -/// _ { -/// let l in 1 .. MAX_LENGTH => initialize_l(l); -/// } -/// /// // first dispatchable: foo; this is a user dispatchable and operates on a `u8` vector of /// // size `l`, which we allow to be initialized as usual. /// foo { From 0c976ab73270609c1b22720c5b6f6089a6ef0e7b Mon Sep 17 00:00:00 2001 From: Stanly Johnson Date: Tue, 5 Jan 2021 11:12:12 +0530 Subject: [PATCH 12/14] fix docs --- frame/benchmarking/src/lib.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/frame/benchmarking/src/lib.rs b/frame/benchmarking/src/lib.rs index 8923ab6c7ff96..1287711b9ab71 100644 --- a/frame/benchmarking/src/lib.rs +++ b/frame/benchmarking/src/lib.rs @@ -89,17 +89,16 @@ pub use sp_storage::TrackedStorageKey; /// where_clause { where T::A: From } // Optional line to give additional bound on `T`. /// /// // first dispatchable: foo; this is a user dispatchable and operates on a `u8` vector of -/// // size `l`, which we allow to be initialized as usual. +/// // size `l` /// foo { /// let caller = account::(b"caller", 0, benchmarks_seed); -/// let l = ...; +/// let l in 1 .. MAX_LENGTH => initialize_l(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 pre-initialized like before so we override using the `=> ()` notation. -/// // In this case, we explicitly name the call using `bar` instead of `_`. +/// // `l`. /// bar { -/// let l = _ .. _ => (); +/// let l in 1 .. MAX_LENGTH => initialize_l(l); /// }: bar(Origin::Root, vec![0u8; l]) /// /// // third dispatchable: baz; this is a user dispatchable. It isn't dependent on length like the From f05516172df3cb322e613e2cc0aa5fe1de94a762 Mon Sep 17 00:00:00 2001 From: Stanly Johnson Date: Tue, 5 Jan 2021 11:15:27 +0530 Subject: [PATCH 13/14] removed too much --- frame/benchmarking/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/frame/benchmarking/src/lib.rs b/frame/benchmarking/src/lib.rs index 1287711b9ab71..6db8674a3d2de 100644 --- a/frame/benchmarking/src/lib.rs +++ b/frame/benchmarking/src/lib.rs @@ -97,6 +97,7 @@ pub use sp_storage::TrackedStorageKey; /// /// // second dispatchable: bar; this is a root dispatchable and accepts a `u8` vector of size /// // `l`. +/// // In this case, we explicitly name the call using `bar` instead of `_`. /// bar { /// let l in 1 .. MAX_LENGTH => initialize_l(l); /// }: bar(Origin::Root, vec![0u8; l]) From 7108fe6d056666a7195b5b330ca34805a8d3372c Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Tue, 5 Jan 2021 10:09:24 -0400 Subject: [PATCH 14/14] fix changes --- frame/identity/src/benchmarking.rs | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/frame/identity/src/benchmarking.rs b/frame/identity/src/benchmarking.rs index 1a0ba284ce11e..e916bdfa50461 100644 --- a/frame/identity/src/benchmarking.rs +++ b/frame/identity/src/benchmarking.rs @@ -117,13 +117,7 @@ benchmarks! { set_identity { let r in 1 .. T::MaxRegistrars::get() => add_registrars::(r)?; - let x in 1 .. T::MaxAdditionalFields::get() => { - // Create their main identity with x additional fields - let info = create_identity_info::(x); - let caller: T::AccountId = whitelisted_caller(); - let caller_origin = ::Origin::from(RawOrigin::Signed(caller)); - Identity::::set_identity(caller_origin, info)?; - }; + let x in 1 .. T::MaxAdditionalFields::get(); let caller = { // The target user let caller: T::AccountId = whitelisted_caller(); @@ -329,18 +323,8 @@ benchmarks! { kill_identity { let r in 1 .. T::MaxRegistrars::get() => add_registrars::(r)?; - let s in 1 .. T::MaxSubAccounts::get() => { - // Give them s many sub accounts - let caller: T::AccountId = whitelisted_caller(); - let _ = add_sub_accounts::(&caller, s)?; - }; - let x in 1 .. T::MaxAdditionalFields::get() => { - // Create their main identity with x additional fields - let info = create_identity_info::(x); - let caller: T::AccountId = whitelisted_caller(); - let caller_origin = ::Origin::from(RawOrigin::Signed(caller)); - Identity::::set_identity(caller_origin, info)?; - }; + let s in 1 .. T::MaxSubAccounts::get(); + let x in 1 .. T::MaxAdditionalFields::get(); let target: T::AccountId = account("target", 0, SEED); let target_origin: ::Origin = RawOrigin::Signed(target.clone()).into();