mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 06:21:11 +00:00
Run Runtime Benchmarks on Block One (#5509)
* Run benchmarks on block 1 * Put example benchmarks behind feature flag * add feature to cargo.toml * typo * Add `frame_system` trait bound * Update instance benchmarks too
This commit is contained in:
@@ -504,7 +504,9 @@ macro_rules! impl_benchmark {
|
|||||||
(
|
(
|
||||||
NO_INSTANCE $( $name:ident ),*
|
NO_INSTANCE $( $name:ident ),*
|
||||||
) => {
|
) => {
|
||||||
impl<T: Trait> $crate::Benchmarking<$crate::BenchmarkResults> for Module<T> {
|
impl<T: Trait> $crate::Benchmarking<$crate::BenchmarkResults> for Module<T>
|
||||||
|
where T: frame_system::Trait
|
||||||
|
{
|
||||||
fn benchmarks() -> Vec<&'static [u8]> {
|
fn benchmarks() -> Vec<&'static [u8]> {
|
||||||
vec![ $( stringify!($name).as_ref() ),* ]
|
vec![ $( stringify!($name).as_ref() ),* ]
|
||||||
}
|
}
|
||||||
@@ -567,6 +569,8 @@ macro_rules! impl_benchmark {
|
|||||||
|
|
||||||
// Run the benchmark `repeat` times.
|
// Run the benchmark `repeat` times.
|
||||||
for _ in 0..repeat {
|
for _ in 0..repeat {
|
||||||
|
// Set the block number to 1 so events are deposited.
|
||||||
|
frame_system::Module::<T>::set_block_number(1.into());
|
||||||
// Set up the externalities environment for the setup we want to benchmark.
|
// Set up the externalities environment for the setup we want to benchmark.
|
||||||
let closure_to_benchmark = <SelectedBenchmark as $crate::BenchmarkingSetup<T>>::instance(&selected_benchmark, &c)?;
|
let closure_to_benchmark = <SelectedBenchmark as $crate::BenchmarkingSetup<T>>::instance(&selected_benchmark, &c)?;
|
||||||
|
|
||||||
@@ -600,7 +604,9 @@ macro_rules! impl_benchmark {
|
|||||||
(
|
(
|
||||||
INSTANCE $( $name:ident ),*
|
INSTANCE $( $name:ident ),*
|
||||||
) => {
|
) => {
|
||||||
impl<T: Trait<I>, I: Instance> $crate::Benchmarking<$crate::BenchmarkResults> for Module<T, I> {
|
impl<T: Trait<I>, I: Instance> $crate::Benchmarking<$crate::BenchmarkResults> for Module<T, I>
|
||||||
|
where T: frame_system::Trait
|
||||||
|
{
|
||||||
fn benchmarks() -> Vec<&'static [u8]> {
|
fn benchmarks() -> Vec<&'static [u8]> {
|
||||||
vec![ $( stringify!($name).as_ref() ),* ]
|
vec![ $( stringify!($name).as_ref() ),* ]
|
||||||
}
|
}
|
||||||
@@ -663,6 +669,8 @@ macro_rules! impl_benchmark {
|
|||||||
|
|
||||||
// Run the benchmark `repeat` times.
|
// Run the benchmark `repeat` times.
|
||||||
for _ in 0..repeat {
|
for _ in 0..repeat {
|
||||||
|
// Set the block number to 1 so events are deposited.
|
||||||
|
frame_system::Module::<T>::set_block_number(1.into());
|
||||||
// Set up the externalities environment for the setup we want to benchmark.
|
// Set up the externalities environment for the setup we want to benchmark.
|
||||||
let closure_to_benchmark = <SelectedBenchmark as $crate::BenchmarkingSetupInstance<T, I>>::instance(&selected_benchmark, &c)?;
|
let closure_to_benchmark = <SelectedBenchmark as $crate::BenchmarkingSetupInstance<T, I>>::instance(&selected_benchmark, &c)?;
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ description = "FRAME example pallet"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1.0.101", optional = true }
|
serde = { version = "1.0.101", optional = true }
|
||||||
codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false }
|
codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false }
|
||||||
frame-benchmarking = { version = "2.0.0-alpha.5", default-features = false, path = "../benchmarking" }
|
|
||||||
frame-support = { version = "2.0.0-alpha.5", default-features = false, path = "../support" }
|
frame-support = { version = "2.0.0-alpha.5", default-features = false, path = "../support" }
|
||||||
frame-system = { version = "2.0.0-alpha.5", default-features = false, path = "../system" }
|
frame-system = { version = "2.0.0-alpha.5", default-features = false, path = "../system" }
|
||||||
pallet-balances = { version = "2.0.0-alpha.5", default-features = false, path = "../balances" }
|
pallet-balances = { version = "2.0.0-alpha.5", default-features = false, path = "../balances" }
|
||||||
@@ -19,6 +18,8 @@ sp-runtime = { version = "2.0.0-alpha.5", default-features = false, path = "../.
|
|||||||
sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" }
|
sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" }
|
||||||
sp-io = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/io" }
|
sp-io = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/io" }
|
||||||
|
|
||||||
|
frame-benchmarking = { version = "2.0.0-alpha.5", default-features = false, path = "../benchmarking", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
sp-core = { version = "2.0.0-alpha.5", path = "../../primitives/core", default-features = false }
|
sp-core = { version = "2.0.0-alpha.5", path = "../../primitives/core", default-features = false }
|
||||||
|
|
||||||
@@ -35,6 +36,7 @@ std = [
|
|||||||
"sp-io/std",
|
"sp-io/std",
|
||||||
"sp-std/std"
|
"sp-std/std"
|
||||||
]
|
]
|
||||||
|
runtime-benchmarks = ["frame-benchmarking"]
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
targets = ["x86_64-unknown-linux-gnu"]
|
targets = ["x86_64-unknown-linux-gnu"]
|
||||||
|
|||||||
@@ -262,8 +262,7 @@ use frame_support::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
use sp_std::prelude::*;
|
use sp_std::prelude::*;
|
||||||
use frame_benchmarking::{benchmarks, account};
|
use frame_system::{self as system, ensure_signed, ensure_root};
|
||||||
use frame_system::{self as system, ensure_signed, ensure_root, RawOrigin};
|
|
||||||
use codec::{Encode, Decode};
|
use codec::{Encode, Decode};
|
||||||
use sp_runtime::{
|
use sp_runtime::{
|
||||||
traits::{SignedExtension, Bounded, SaturatedConversion},
|
traits::{SignedExtension, Bounded, SaturatedConversion},
|
||||||
@@ -651,39 +650,46 @@ impl<T: Trait + Send + Sync> SignedExtension for WatchDummy<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
benchmarks!{
|
#[cfg(feature = "runtime-benchmarks")]
|
||||||
_ {
|
mod benchmarking {
|
||||||
// Define a common range for `b`.
|
use super::*;
|
||||||
let b in 1 .. 1000 => ();
|
use frame_benchmarking::{benchmarks, account};
|
||||||
}
|
use frame_system::RawOrigin;
|
||||||
|
|
||||||
// This will measure the execution time of `accumulate_dummy` for b in [1..1000] range.
|
benchmarks!{
|
||||||
accumulate_dummy {
|
_ {
|
||||||
let b in ...;
|
// Define a common range for `b`.
|
||||||
let caller = account("caller", 0, 0);
|
let b in 1 .. 1000 => ();
|
||||||
}: _ (RawOrigin::Signed(caller), b.into())
|
}
|
||||||
|
|
||||||
// This will measure the execution time of `set_dummy` for b in [1..1000] range.
|
// This will measure the execution time of `accumulate_dummy` for b in [1..1000] range.
|
||||||
set_dummy {
|
accumulate_dummy {
|
||||||
let b in ...;
|
let b in ...;
|
||||||
let caller = account("caller", 0, 0);
|
let caller = account("caller", 0, 0);
|
||||||
}: set_dummy (RawOrigin::Signed(caller), b.into())
|
}: _ (RawOrigin::Signed(caller), b.into())
|
||||||
|
|
||||||
// This will measure the execution time of `set_dummy` for b in [1..10] range.
|
// This will measure the execution time of `set_dummy` for b in [1..1000] range.
|
||||||
another_set_dummy {
|
set_dummy {
|
||||||
let b in 1 .. 10;
|
let b in ...;
|
||||||
let caller = account("caller", 0, 0);
|
let caller = account("caller", 0, 0);
|
||||||
}: set_dummy (RawOrigin::Signed(caller), b.into())
|
}: set_dummy (RawOrigin::Signed(caller), b.into())
|
||||||
|
|
||||||
// This will measure the execution time of sorting a vector.
|
// This will measure the execution time of `set_dummy` for b in [1..10] range.
|
||||||
sort_vector {
|
another_set_dummy {
|
||||||
let x in 0 .. 10000;
|
let b in 1 .. 10;
|
||||||
let mut m = Vec::<u32>::new();
|
let caller = account("caller", 0, 0);
|
||||||
for i in 0..x {
|
}: set_dummy (RawOrigin::Signed(caller), b.into())
|
||||||
m.push(i);
|
|
||||||
|
// This will measure the execution time of sorting a vector.
|
||||||
|
sort_vector {
|
||||||
|
let x in 0 .. 10000;
|
||||||
|
let mut m = Vec::<u32>::new();
|
||||||
|
for i in 0..x {
|
||||||
|
m.push(i);
|
||||||
|
}
|
||||||
|
}: {
|
||||||
|
m.sort();
|
||||||
}
|
}
|
||||||
}: {
|
|
||||||
m.sort();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user