mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-06 02:08:02 +00:00
Benchmark Timestamp Pallet (#4891)
* Add selected_benchmark! macro. * Use selected_benchmark! in Identity pallet. * Implement timestamp pallet benchmark. * Fix some nits. * Bump impl_version.
This commit is contained in:
@@ -1333,6 +1333,55 @@ pub trait BenchmarkingSetup<T, Call, RawOrigin> {
|
||||
fn instance(&self, components: &[(BenchmarkParameter, u32)]) -> Result<(Call, RawOrigin), &'static str>;
|
||||
}
|
||||
|
||||
/// Creates a `SelectedBenchmark` enum implementing `BenchmarkingSetup`.
|
||||
///
|
||||
/// Every variant must implement [`BenchmarkingSetup`](crate::traits::BenchmarkingSetup).
|
||||
///
|
||||
/// ```nocompile
|
||||
///
|
||||
/// struct Transfer;
|
||||
/// impl BenchmarkingSetup for Transfer { ... }
|
||||
///
|
||||
/// struct SetBalance;
|
||||
/// impl BenchmarkingSetup for SetBalance { ... }
|
||||
///
|
||||
/// selected_benchmark!(Transfer, SetBalance);
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! selected_benchmark {
|
||||
($($bench:ident),*) => {
|
||||
// The list of available benchmarks for this pallet.
|
||||
enum SelectedBenchmark {
|
||||
$( $bench, )*
|
||||
}
|
||||
|
||||
// Allow us to select a benchmark from the list of available benchmarks.
|
||||
impl<T: Trait> $crate::traits::BenchmarkingSetup<T, Call<T>, RawOrigin<T::AccountId>> for SelectedBenchmark {
|
||||
fn components(&self) -> Vec<(BenchmarkParameter, u32, u32)> {
|
||||
match self {
|
||||
$( Self::$bench => <$bench as $crate::traits::BenchmarkingSetup<
|
||||
T,
|
||||
Call<T>,
|
||||
RawOrigin<T::AccountId>,
|
||||
>>::components(&$bench), )*
|
||||
}
|
||||
}
|
||||
|
||||
fn instance(&self, components: &[(BenchmarkParameter, u32)])
|
||||
-> Result<(Call<T>, RawOrigin<T::AccountId>), &'static str>
|
||||
{
|
||||
match self {
|
||||
$( Self::$bench => <$bench as $crate::traits::BenchmarkingSetup<
|
||||
T,
|
||||
Call<T>,
|
||||
RawOrigin<T::AccountId>,
|
||||
>>::instance(&$bench, components), )*
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user