difftreelog
feat(fungible) benchmarking
in: master
5 files changed
pallets/fungible/Cargo.tomldiffbeforeafterboth20evm-coder = { default-features = false, path = '../../crates/evm-coder' }20evm-coder = { default-features = false, path = '../../crates/evm-coder' }21ethereum = { default-features = false, version = "0.9.0" }21ethereum = { default-features = false, version = "0.9.0" }22pallet-evm-coder-substrate = { default-features = false, path = '../evm-coder-substrate' }22pallet-evm-coder-substrate = { default-features = false, path = '../evm-coder-substrate' }23frame-benchmarking = { default-features = false, optional = true, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.10' }232424[features]25[features]25default = ["std"]26default = ["std"]32 "pallet-common/std",33 "pallet-common/std",33 "evm-coder/std",34 "evm-coder/std",34 "ethereum/std",35 "ethereum/std",36 'frame-benchmarking/std',35]37]36runtime-benchmarks = []38runtime-benchmarks = [39 'frame-benchmarking',40 'pallet-common/runtime-benchmarks',41]3742pallets/fungible/src/benchmarking.rsdiffbeforeafterboth1use super::*;2use crate::{Pallet, Config, FungibleHandle};34use sp_std::prelude::*;5use pallet_common::benchmarking::create_collection_raw;6use frame_benchmarking::{benchmarks, account};7use nft_data_structs::{CollectionMode};8use pallet_common::bench_init;910const SEED: u32 = 1;1112fn create_collection<T: Config>(owner: T::AccountId) -> Result<FungibleHandle<T>, DispatchError> {13 create_collection_raw(14 owner,15 CollectionMode::Fungible(0),16 <Pallet<T>>::init_collection,17 FungibleHandle::cast,18 )19}201#![cfg(feature = "runtime-benchmarking")]21benchmarks! {22 create_item {23 bench_init!{24 owner: sub; collection: collection(owner);25 sender: cross_from_sub(owner); to: cross_sub;26 };27 }: {<Pallet<T>>::create_item(&collection, &sender, (to, 200))?}2829 burn_item {30 bench_init!{31 owner: sub; collection: collection(owner);32 owner: cross_from_sub; burner: cross_sub;33 };34 <Pallet<T>>::create_item(&collection, &owner, (burner.clone(), 200))?;35 }: {<Pallet<T>>::burn(&collection, &burner, 100)?}3637 transfer {38 bench_init!{39 owner: sub; collection: collection(owner);40 owner: cross_from_sub; sender: cross_sub; to: cross_sub;41 };42 <Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200))?;43 }: {<Pallet<T>>::transfer(&collection, &sender, &to, 200)?}4445 approve {46 bench_init!{47 owner: sub; collection: collection(owner);48 owner: cross_from_sub; sender: cross_sub; spender: cross_sub;49 };50 <Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200))?;51 }: {<Pallet<T>>::set_allowance(&collection, &sender, &spender, 100)?}5253 transfer_from {54 bench_init!{55 owner: sub; collection: collection(owner);56 owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub;57 };58 <Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200))?;59 <Pallet<T>>::set_allowance(&collection, &sender, &spender, 200)?;60 }: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, 100)?}61}262pallets/fungible/src/common.rsdiffbeforeafterboth54 match data {54 match data {55 nft_data_structs::CreateItemData::Fungible(data) => with_weight(55 nft_data_structs::CreateItemData::Fungible(data) => with_weight(56 <Pallet<T>>::create_item(self, &sender, (to, data.value)),56 <Pallet<T>>::create_item(self, &sender, (to, data.value)),57 <SelfWeightOf<T>>::create_item(),57 <CommonWeights<T>>::create_item(),58 ),58 ),59 _ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),59 _ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),60 }60 }808081 with_weight(81 with_weight(82 <Pallet<T>>::create_item(self, &sender, (to, sum)),82 <Pallet<T>>::create_item(self, &sender, (to, sum)),83 <SelfWeightOf<T>>::create_item(),83 <CommonWeights<T>>::create_item(),84 )84 )85 }85 }8686979798 with_weight(98 with_weight(99 <Pallet<T>>::burn(self, &sender, amount),99 <Pallet<T>>::burn(self, &sender, amount),100 <SelfWeightOf<T>>::burn_item(),100 <CommonWeights<T>>::burn_item(),101 )101 )102 }102 }103103115115116 with_weight(116 with_weight(117 <Pallet<T>>::transfer(&self, &from, &to, amount),117 <Pallet<T>>::transfer(&self, &from, &to, amount),118 <SelfWeightOf<T>>::transfer(),118 <CommonWeights<T>>::transfer(),119 )119 )120 }120 }121121133133134 with_weight(134 with_weight(135 <Pallet<T>>::set_allowance(&self, &sender, &spender, amount),135 <Pallet<T>>::set_allowance(&self, &sender, &spender, amount),136 <SelfWeightOf<T>>::approve(),136 <CommonWeights<T>>::approve(),137 )137 )138 }138 }139139152152153 with_weight(153 with_weight(154 <Pallet<T>>::transfer_from(&self, &sender, &from, &to, amount),154 <Pallet<T>>::transfer_from(&self, &sender, &from, &to, amount),155 <SelfWeightOf<T>>::transfer_from(),155 <CommonWeights<T>>::transfer_from(),156 )156 )157 }157 }158158pallets/fungible/src/lib.rsdiffbeforeafterboth13pub use pallet::*;13pub use pallet::*;141415use crate::erc::ERC20Events;15use crate::erc::ERC20Events;16#[cfg(feature = "runtime-benchmarks")]16pub mod benchmarking;17pub mod benchmarking;17pub mod common;18pub mod common;18pub mod erc;19pub mod erc;pallets/fungible/src/weights.rsdiffbeforeafterboth1// Template adopted from https://github.com/paritytech/substrate/blob/master/.maintain/frame-weight-template.hbs23//! Autogenerated weights for pallet_fungible4//!5//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev6//! DATE: 2021-10-21, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`7//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 12889// Executed Command:10// target/release/nft11// benchmark12// --pallet13// pallet-fungible14// --wasm-execution15// compiled16// --extrinsic17// *18// --template19// .maintain/frame-weight-template.hbs20// --steps=5021// --repeat=2022// --output=./pallets/fungible/src/weights.rs23241#![cfg_attr(rustfmt, rustfmt_skip)]25#![cfg_attr(rustfmt, rustfmt_skip)]5use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};29use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};6use sp_std::marker::PhantomData;30use sp_std::marker::PhantomData;73132/// Weight functions needed for pallet_fungible.8pub trait WeightInfo {33pub trait WeightInfo {9 fn create_item() -> Weight;34 fn create_item() -> Weight;10 fn burn_item() -> Weight;35 fn burn_item() -> Weight;13 fn transfer_from() -> Weight;38 fn transfer_from() -> Weight;14}39}154041/// Weights for pallet_fungible using the Substrate node and recommended hardware.16pub struct SubstrateWeight<T>(PhantomData<T>);42pub struct SubstrateWeight<T>(PhantomData<T>);17impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {43impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {44 // Storage: Fungible Balance (r:1 w:1)45 // Storage: Fungible TotalSupply (r:0 w:1)18 fn create_item() -> Weight {0}46 fn create_item() -> Weight {47 (12_069_000 as Weight)48 .saturating_add(T::DbWeight::get().reads(1 as Weight))49 .saturating_add(T::DbWeight::get().writes(2 as Weight))50 }51 // Storage: Fungible TotalSupply (r:1 w:1)52 // Storage: Fungible Balance (r:1 w:1)19 fn burn_item() -> Weight {0}53 fn burn_item() -> Weight {54 (14_096_000 as Weight)55 .saturating_add(T::DbWeight::get().reads(2 as Weight))56 .saturating_add(T::DbWeight::get().writes(2 as Weight))57 }58 // Storage: Fungible Balance (r:2 w:2)20 fn transfer() -> Weight {0}59 fn transfer() -> Weight {60 (15_436_000 as Weight)61 .saturating_add(T::DbWeight::get().reads(2 as Weight))62 .saturating_add(T::DbWeight::get().writes(2 as Weight))63 }64 // Storage: Fungible Balance (r:1 w:0)65 // Storage: Fungible Allowance (r:0 w:1)21 fn approve() -> Weight {0}66 fn approve() -> Weight {67 (12_867_000 as Weight)68 .saturating_add(T::DbWeight::get().reads(1 as Weight))69 .saturating_add(T::DbWeight::get().writes(1 as Weight))70 }71 // Storage: Fungible Allowance (r:1 w:1)72 // Storage: Fungible Balance (r:2 w:2)22 fn transfer_from() -> Weight {0}73 fn transfer_from() -> Weight {74 (21_462_000 as Weight)75 .saturating_add(T::DbWeight::get().reads(3 as Weight))76 .saturating_add(T::DbWeight::get().writes(3 as Weight))77 }23}78}247980// For backwards compatibility and tests25impl WeightInfo for () {81impl WeightInfo for () {82 // Storage: Fungible Balance (r:1 w:1)83 // Storage: Fungible TotalSupply (r:0 w:1)26 fn create_item() -> Weight {0}84 fn create_item() -> Weight {85 (12_069_000 as Weight)86 .saturating_add(RocksDbWeight::get().reads(1 as Weight))87 .saturating_add(RocksDbWeight::get().writes(2 as Weight))88 }89 // Storage: Fungible TotalSupply (r:1 w:1)90 // Storage: Fungible Balance (r:1 w:1)27 fn burn_item() -> Weight {0}91 fn burn_item() -> Weight {92 (14_096_000 as Weight)93 .saturating_add(RocksDbWeight::get().reads(2 as Weight))94 .saturating_add(RocksDbWeight::get().writes(2 as Weight))95 }96 // Storage: Fungible Balance (r:2 w:2)28 fn transfer() -> Weight {0}97 fn transfer() -> Weight {98 (15_436_000 as Weight)99 .saturating_add(RocksDbWeight::get().reads(2 as Weight))100 .saturating_add(RocksDbWeight::get().writes(2 as Weight))101 }102 // Storage: Fungible Balance (r:1 w:0)103 // Storage: Fungible Allowance (r:0 w:1)29 fn approve() -> Weight {0}104 fn approve() -> Weight {105 (12_867_000 as Weight)106 .saturating_add(RocksDbWeight::get().reads(1 as Weight))107 .saturating_add(RocksDbWeight::get().writes(1 as Weight))108 }109 // Storage: Fungible Allowance (r:1 w:1)110 // Storage: Fungible Balance (r:2 w:2)30 fn transfer_from() -> Weight {0}111 fn transfer_from() -> Weight {112 (21_462_000 as Weight)113 .saturating_add(RocksDbWeight::get().reads(3 as Weight))114 .saturating_add(RocksDbWeight::get().writes(3 as Weight))115 }31}116}32117