mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 04:07:57 +00:00
generation of real benchmark functions for benchmarking v2 (#13224)
* function generation with _name working, need to modify signature * WIP * support custom BenchmarkResult<T> type * full support for BenchmarkResult<T> on benchmark function defs * support () return type for benchmark function defs that don't use ? * uncomment * fix where clause handling * fix benchmark function call bodies * proper parsing of return type * add UI tests for bad return type * fix detection of missing last_stmt with defined return type * UI tests covering missing last_stmt * properly detect and complain about empty benchmark function defs * fix missing Comma in Result<T, BenchmarkError> parsing + test * add additional UI test * allow complex path for BenchmarkResult and BenchmarkError in fn defs * add UI tests covering complex path for BenchmarkResult, BenchmarkError * retain doc comments and attributes * also add attributes to struct * add docs for benchmark function definition support * fix imports on benchmark example * fix issue with unused variables in extrinsic call fn def * fix up docs * remove support for v2::BenchmarkResult because it was confusing * fix typo * remove ability to use custom T for Result<T, BenchmarkError> in v2 * use missing call error instead of empty_fn() * remove unneeded match statement * Add a proper QED Co-authored-by: Keith Yeung <kungfukeith11@gmail.com> * fix other QED Co-authored-by: Keith Yeung <kungfukeith11@gmail.com> * cargo fmt * add an explicit error for non TypePath as return type * tweak error warning and add a UI test for non TypePath return * remove comment * add docs about T and I generic params * improve docs referring to section "below" * pull out return type checking logic into its own function * pull out params parsing into its own function * pull out call_def parsing into its own function * add doc comment for missing_call() * replace spaces with tabs * add a result-based example to the benchmarking examples --------- Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
This commit is contained in:
@@ -21,11 +21,7 @@
|
||||
#![cfg(feature = "runtime-benchmarks")]
|
||||
|
||||
use crate::*;
|
||||
use frame_benchmarking::v1::{
|
||||
impl_benchmark_test_suite,
|
||||
v2::{benchmarks, Linear},
|
||||
whitelisted_caller,
|
||||
};
|
||||
use frame_benchmarking::v2::*;
|
||||
use frame_system::RawOrigin;
|
||||
|
||||
// To actually run this benchmark on pallet-example-basic, we need to put this pallet into the
|
||||
@@ -55,19 +51,31 @@ mod benchmarks {
|
||||
assert_eq!(Pallet::<T>::dummy(), Some(value))
|
||||
}
|
||||
|
||||
// An example method that returns a Result that can be called within a benchmark
|
||||
fn example_result_method() -> Result<(), BenchmarkError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// This will measure the execution time of `accumulate_dummy`.
|
||||
// The benchmark execution phase is shorthanded. When the name of the benchmark case is the same
|
||||
// as the extrinsic call. `_(...)` is used to represent the extrinsic name.
|
||||
// The benchmark verification phase is omitted.
|
||||
#[benchmark]
|
||||
fn accumulate_dummy() {
|
||||
fn accumulate_dummy() -> Result<(), BenchmarkError> {
|
||||
let value = 1000u32.into();
|
||||
// The caller account is whitelisted for DB reads/write by the benchmarking macro.
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
|
||||
// an example of calling something result-based within a benchmark using the ? operator
|
||||
// this necessitates specifying the `Result<(), BenchmarkError>` return type
|
||||
example_result_method()?;
|
||||
|
||||
// You can use `_` if the name of the Call matches the benchmark name.
|
||||
#[extrinsic_call]
|
||||
_(RawOrigin::Signed(caller), value);
|
||||
|
||||
// need this to be compatible with the return type
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// You can write helper functions in here since its a normal Rust module.
|
||||
|
||||
Reference in New Issue
Block a user