Update benchmarking macros (#3934)

Current benchmarking macro returns a closure with the captured
benchmarked code.
This can cause issues when the benchmarked code has complex lifetime
requirements.

This PR updates the existing macro by injecting the recording parameter
and invoking the start / stop method around the benchmarked block
instead of returning a closure

One other added benefit is that you can write this kind of code now as
well:

```rust
let v;
#[block]
{ v = func.call(); }
dbg!(v); // or assert something on v
```


[Weights compare
link](https://weights.tasty.limo/compare?unit=weight&ignore_errors=true&threshold=10&method=asymptotic&repo=polkadot-sdk&old=pg/fix-weights&new=pg/bench_update&path_pattern=substrate/frame/**/src/weights.rs,polkadot/runtime/*/src/weights/**/*.rs,polkadot/bridges/modules/*/src/weights.rs,cumulus/**/weights/*.rs,cumulus/**/weights/xcm/*.rs,cumulus/**/src/weights.rs)

---------

Co-authored-by: command-bot <>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
This commit is contained in:
PG Herveou
2024-04-10 08:44:46 +02:00
committed by GitHub
parent ddb53c87f5
commit d38f6e6728
65 changed files with 11402 additions and 10551 deletions
@@ -15,24 +15,23 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-06-16 (Y/M/D)
//! HOSTNAME: `runner-e8ezs4ez-project-145-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2024-04-08 (Y/M/D)
//! HOSTNAME: `runner-anb7yjbi-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
//!
//! SHORT-NAME: `block`, LONG-NAME: `BlockExecution`, RUNTIME: `Development`
//! WARMUPS: `10`, REPEAT: `100`
//! WEIGHT-PATH: `./frame/support/src/weights/`
//! WEIGHT-PATH: `./substrate/frame/support/src/weights/`
//! WEIGHT-METRIC: `Average`, WEIGHT-MUL: `1.0`, WEIGHT-ADD: `0`
// Executed Command:
// ./target/production/substrate
// ./target/production/substrate-node
// benchmark
// overhead
// --chain=dev
// --execution=wasm
// --wasm-execution=compiled
// --weight-path=./frame/support/src/weights/
// --header=./HEADER-APACHE2
// --weight-path=./substrate/frame/support/src/weights/
// --header=./substrate/HEADER-APACHE2
// --warmup=10
// --repeat=100
@@ -44,17 +43,17 @@ parameter_types! {
/// Calculated by multiplying the *Average* with `1.0` and adding `0`.
///
/// Stats nanoseconds:
/// Min, Max: 376_949, 622_462
/// Average: 390_584
/// Median: 386_322
/// Std-Dev: 24792.0
/// Min, Max: 440_235, 661_535
/// Average: 453_383
/// Median: 449_925
/// Std-Dev: 22021.99
///
/// Percentiles nanoseconds:
/// 99th: 433_299
/// 95th: 402_688
/// 75th: 391_645
/// 99th: 474_045
/// 95th: 466_455
/// 75th: 455_056
pub const BlockExecutionWeight: Weight =
Weight::from_parts(WEIGHT_REF_TIME_PER_NANOS.saturating_mul(390_584), 0);
Weight::from_parts(WEIGHT_REF_TIME_PER_NANOS.saturating_mul(453_383), 0);
}
#[cfg(test)]
@@ -15,24 +15,23 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-06-16 (Y/M/D)
//! HOSTNAME: `runner-e8ezs4ez-project-145-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2024-04-08 (Y/M/D)
//! HOSTNAME: `runner-anb7yjbi-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
//!
//! SHORT-NAME: `extrinsic`, LONG-NAME: `ExtrinsicBase`, RUNTIME: `Development`
//! WARMUPS: `10`, REPEAT: `100`
//! WEIGHT-PATH: `./frame/support/src/weights/`
//! WEIGHT-PATH: `./substrate/frame/support/src/weights/`
//! WEIGHT-METRIC: `Average`, WEIGHT-MUL: `1.0`, WEIGHT-ADD: `0`
// Executed Command:
// ./target/production/substrate
// ./target/production/substrate-node
// benchmark
// overhead
// --chain=dev
// --execution=wasm
// --wasm-execution=compiled
// --weight-path=./frame/support/src/weights/
// --header=./HEADER-APACHE2
// --weight-path=./substrate/frame/support/src/weights/
// --header=./substrate/HEADER-APACHE2
// --warmup=10
// --repeat=100
@@ -44,17 +43,17 @@ parameter_types! {
/// Calculated by multiplying the *Average* with `1.0` and adding `0`.
///
/// Stats nanoseconds:
/// Min, Max: 123_875, 128_419
/// Average: 124_414
/// Median: 124_332
/// Std-Dev: 497.74
/// Min, Max: 106_559, 107_788
/// Average: 107_074
/// Median: 107_067
/// Std-Dev: 242.67
///
/// Percentiles nanoseconds:
/// 99th: 125_245
/// 95th: 124_989
/// 75th: 124_498
/// 99th: 107_675
/// 95th: 107_513
/// 75th: 107_225
pub const ExtrinsicBaseWeight: Weight =
Weight::from_parts(WEIGHT_REF_TIME_PER_NANOS.saturating_mul(124_414), 0);
Weight::from_parts(WEIGHT_REF_TIME_PER_NANOS.saturating_mul(107_074), 0);
}
#[cfg(test)]