-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(benchmark): benchmarking pallets [2/4] (#698)
- Loading branch information
Showing
33 changed files
with
1,259 additions
and
355 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#![cfg(feature = "runtime-benchmarks")] | ||
|
||
use super::*; | ||
use crate::Pallet as BurningModule; | ||
use frame_benchmarking::{benchmarks, whitelisted_caller}; | ||
use frame_system::{EventRecord, Pallet as System, RawOrigin}; | ||
use sp_runtime::{traits::StaticLookup, SaturatedConversion}; | ||
|
||
benchmarks! { | ||
// burn_tft() | ||
burn_tft { | ||
let target: T::AccountId = whitelisted_caller(); | ||
let target_lookup = T::Lookup::unlookup(target.clone()); | ||
let amount = BalanceOf::<T>::saturated_from(1000 as u128); | ||
T::Currency::make_free_balance_be(&target, amount); | ||
let message = b"some_message".to_vec(); | ||
}: _(RawOrigin::Signed(target.clone()), amount.clone(), message.clone()) | ||
verify { | ||
let block = T::BlockNumber::from(1 as u32); | ||
assert_eq!(T::Currency::free_balance(&target).saturated_into::<u128>(), 0 as u128); | ||
assert_last_event::<T>(Event::BurnTransactionCreated(target, amount, block, message).into()); | ||
} | ||
|
||
// Calling the `impl_benchmark_test_suite` macro inside the `benchmarks` | ||
// block will generate one #[test] function per benchmark | ||
impl_benchmark_test_suite!(BurningModule, crate::mock::new_test_ext(), crate::mock::TestRuntime) | ||
} | ||
|
||
fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) { | ||
let events = System::<T>::events(); | ||
let system_event: <T as frame_system::Config>::RuntimeEvent = generic_event.into(); | ||
let EventRecord { event, .. } = &events[events.len() - 1]; | ||
assert_eq!(event, &system_event); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
|
||
//! Autogenerated weights for pallet_burning | ||
//! | ||
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev | ||
//! DATE: 2023-05-16, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` | ||
//! HOSTNAME: `R1-HP-ProBook-630-G8`, CPU: `11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz` | ||
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 | ||
|
||
// Executed Command: | ||
// ./target/release/tfchain | ||
// benchmark | ||
// pallet | ||
// --chain=dev | ||
// --pallet=pallet_burning | ||
// --extrinsic=* | ||
// --steps=50 | ||
// --repeat=20 | ||
// --execution=wasm | ||
// --heap-pages=4096 | ||
// --output | ||
// pallets/pallet-burning/src/weights.rs | ||
// --template | ||
// ./.maintain/frame-weight-template.hbs | ||
|
||
#![cfg_attr(rustfmt, rustfmt_skip)] | ||
#![allow(unused_parens)] | ||
#![allow(unused_imports)] | ||
|
||
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; | ||
use sp_std::marker::PhantomData; | ||
|
||
/// Weight functions needed for pallet_burning. | ||
pub trait WeightInfo { | ||
fn burn_tft() -> Weight; | ||
} | ||
|
||
/// Weights for pallet_burning using the Substrate node and recommended hardware. | ||
pub struct SubstrateWeight<T>(PhantomData<T>); | ||
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { | ||
// Storage: BurningModule Burns (r:1 w:1) | ||
fn burn_tft() -> Weight { | ||
// Minimum execution time: 58_615 nanoseconds. | ||
Weight::from_ref_time(63_829_000) | ||
.saturating_add(T::DbWeight::get().reads(1)) | ||
.saturating_add(T::DbWeight::get().writes(1)) | ||
} | ||
} | ||
|
||
// For backwards compatibility and tests | ||
impl WeightInfo for () { | ||
// Storage: BurningModule Burns (r:1 w:1) | ||
fn burn_tft() -> Weight { | ||
// Minimum execution time: 58_615 nanoseconds. | ||
Weight::from_ref_time(63_829_000) | ||
.saturating_add(RocksDbWeight::get().reads(1)) | ||
.saturating_add(RocksDbWeight::get().writes(1)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.