1
- //! Macro for benchmarking a Substrate runtime. A fork of `frame-benchmarking` pallet.
1
+ //! Macro for benchmarking a Substrate runtime. A fork of `frame-benchmarking`
2
+ //! pallet.
2
3
3
4
#![ cfg_attr( not( feature = "std" ) , no_std) ]
4
5
@@ -19,13 +20,15 @@ pub use sp_runtime::traits::{Dispatchable, One, Zero};
19
20
20
21
/// Construct pallet benchmarks for weighing dispatchables.
21
22
///
22
- /// Works around the idea of complexity parameters, named by a single letter (which is usually
23
- /// upper cased in complexity notation but is lower-cased for use in this macro).
23
+ /// Works around the idea of complexity parameters, named by a single letter
24
+ /// (which is usually upper cased in complexity notation but is lower-cased for
25
+ /// use in this macro).
24
26
///
25
- /// Complexity parameters ("parameters") have a range which is a `u32` pair. Every time a benchmark
26
- /// is prepared and run, this parameter takes a concrete value within the range. There is an
27
- /// associated instancing block, which is a single expression that is evaluated during
28
- /// preparation. It may use `?` (`i.e. `return Err(...)`) to bail with a string error. Here's a
27
+ /// Complexity parameters ("parameters") have a range which is a `u32` pair.
28
+ /// Every time a benchmark is prepared and run, this parameter takes a concrete
29
+ /// value within the range. There is an associated instancing block, which is a
30
+ /// single expression that is evaluated during preparation. It may use `?`
31
+ /// (`i.e. `return Err(...)`) to bail with a string error. Here's a
29
32
/// few examples:
30
33
///
31
34
/// ```ignore
@@ -42,29 +45,32 @@ pub use sp_runtime::traits::{Dispatchable, One, Zero};
42
45
/// }
43
46
/// ```
44
47
///
45
- /// Note that due to parsing restrictions, if the `from` expression is not a single token (i.e. a
46
- /// literal or constant), then it must be parenthesised.
48
+ /// Note that due to parsing restrictions, if the `from` expression is not a
49
+ /// single token (i.e. a literal or constant), then it must be parenthesised.
47
50
///
48
- /// The macro allows for a number of "arms", each representing an individual benchmark. Using the
49
- /// simple syntax, the associated dispatchable function maps 1:1 with the benchmark and the name of
50
- /// the benchmark is the same as that of the associated function. However, extended syntax allows
51
- /// for arbitrary expresions to be evaluated in a benchmark (including for example,
52
- /// `on_initialize`).
51
+ /// The macro allows for a number of "arms", each representing an individual
52
+ /// benchmark. Using the simple syntax, the associated dispatchable function
53
+ /// maps 1:1 with the benchmark and the name of the benchmark is the same as
54
+ /// that of the associated function. However, extended syntax allows
55
+ /// for arbitrary expresions to be evaluated in a benchmark (including for
56
+ /// example, `on_initialize`).
53
57
///
54
- /// The macro allows for common parameters whose ranges and instancing expressions may be drawn upon
55
- /// (or not) by each arm. Syntax is available to allow for only the range to be drawn upon if
56
- /// desired, allowing an alternative instancing expression to be given.
58
+ /// The macro allows for common parameters whose ranges and instancing
59
+ /// expressions may be drawn upon (or not) by each arm. Syntax is available to
60
+ /// allow for only the range to be drawn upon if desired, allowing an
61
+ /// alternative instancing expression to be given.
57
62
///
58
- /// Note that the ranges are *inclusive* on both sides. This is in contrast to ranges in Rust which
59
- /// are left-inclusive right-exclusive.
63
+ /// Note that the ranges are *inclusive* on both sides. This is in contrast to
64
+ /// ranges in Rust which are left-inclusive right-exclusive.
60
65
///
61
- /// Each arm may also have a block of code which is run prior to any instancing and a block of code
62
- /// which is run afterwards. All code blocks may draw upon the specific value of each parameter
63
- /// at any time. Local variables are shared between the two pre- and post- code blocks, but do not
64
- /// leak from the interior of any instancing expressions.
66
+ /// Each arm may also have a block of code which is run prior to any instancing
67
+ /// and a block of code which is run afterwards. All code blocks may draw upon
68
+ /// the specific value of each parameter at any time. Local variables are shared
69
+ /// between the two pre- and post- code blocks, but do not leak from the
70
+ /// interior of any instancing expressions.
65
71
///
66
- /// Any common parameters that are unused in an arm do not have their instancing expressions
67
- /// evaluated.
72
+ /// Any common parameters that are unused in an arm do not have their instancing
73
+ /// expressions evaluated.
68
74
///
69
75
/// Example:
70
76
/// ```ignore
@@ -124,14 +130,16 @@ pub use sp_runtime::traits::{Dispatchable, One, Zero};
124
130
/// }
125
131
/// ```
126
132
///
127
- /// Test functions are automatically generated for each benchmark and are accessible to you when you
128
- /// run `cargo test`. All tests are named `test_benchmark_<benchmark_name>`, expect you to pass them
129
- /// the Runtime Trait, and run them in a test externalities environment. The test function runs your
130
- /// benchmark just like a regular benchmark, but only testing at the lowest and highest values for
131
- /// each component. The function will return `Ok(())` if the benchmarks return no errors.
133
+ /// Test functions are automatically generated for each benchmark and are
134
+ /// accessible to you when you run `cargo test`. All tests are named
135
+ /// `test_benchmark_<benchmark_name>`, expect you to pass them the Runtime
136
+ /// Trait, and run them in a test externalities environment. The test function
137
+ /// runs your benchmark just like a regular benchmark, but only testing at the
138
+ /// lowest and highest values for each component. The function will return
139
+ /// `Ok(())` if the benchmarks return no errors.
132
140
///
133
- /// You can optionally add a `verify` code block at the end of a benchmark to test any final state
134
- /// of your benchmark in a unit test. For example:
141
+ /// You can optionally add a `verify` code block at the end of a benchmark to
142
+ /// test any final state of your benchmark in a unit test. For example:
135
143
///
136
144
/// ```ignore
137
145
/// sort_vector {
@@ -648,7 +656,7 @@ macro_rules! benchmark_backend {
648
656
// Every variant must implement [`BenchmarkingSetup`].
649
657
//
650
658
// ```nocompile
651
- //
659
+ //
652
660
// struct Transfer;
653
661
// impl BenchmarkingSetup for Transfer { ... }
654
662
//
@@ -1142,8 +1150,8 @@ macro_rules! impl_benchmark_test {
1142
1150
/// let mut batches = Vec::<BenchmarkBatch>::new();
1143
1151
/// ````
1144
1152
///
1145
- /// Then add the pallets you want to benchmark to this object, including the string
1146
- /// you want to use target a particular pallet:
1153
+ /// Then add the pallets you want to benchmark to this object, including the
1154
+ /// string you want to use target a particular pallet:
1147
1155
///
1148
1156
/// ```ignore
1149
1157
/// add_benchmark!(params, batches, b"balances", Balances);
0 commit comments