git.delta.rocks / unique-network / refs/commits / 1d469f4695cf

difftreelog

feat(refungible) benchmarking

Yaroslav Bolyukin2021-10-22parent: #4e1bd65.patch.diff
in: master

5 files changed

modifiedpallets/refungible/Cargo.tomldiffbeforeafterboth
--- a/pallets/refungible/Cargo.toml
+++ b/pallets/refungible/Cargo.toml
@@ -17,6 +17,7 @@
 sp-core = { default-features = false, version = '4.0.0-dev', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.10' }
 pallet-common = { default-features = false, path = '../common' }
 nft-data-structs = { default-features = false, path = '../../primitives/nft' }
+frame-benchmarking = { default-features = false, optional = true, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.10' }
 
 [features]
 default = ["std"]
@@ -27,5 +28,10 @@
     "sp-std/std",
     "nft-data-structs/std",
     "pallet-common/std",
+    'frame-benchmarking/std',
+]
+runtime-benchmarks = [
+    'frame-benchmarking',
+    'frame-support/runtime-benchmarks',
+    'frame-system/runtime-benchmarks',
 ]
-runtime-benchmarks = []
modifiedpallets/refungible/src/benchmarking.rsdiffbeforeafterboth
before · pallets/refungible/src/benchmarking.rs
1#![cfg(feature = "runtime-benchmarking")]
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -14,6 +14,15 @@
 	RefungibleHandle, SelfWeightOf, TokenData, weights::WeightInfo, TokensMinted,
 };
 
+macro_rules! max_weight_of {
+	($($method:ident ($($args:tt)*)),*) => {
+		0
+		$(
+			.max(<SelfWeightOf<T>>::$method($($args)*))
+		)*
+	};
+}
+
 pub struct CommonWeights<T: Config>(PhantomData<T>);
 impl<T: Config> CommonWeightInfo for CommonWeights<T> {
 	fn create_item() -> Weight {
@@ -25,11 +34,16 @@
 	}
 
 	fn burn_item() -> Weight {
-		<SelfWeightOf<T>>::burn_item()
+		max_weight_of!(burn_item_partial(), burn_item_fully())
 	}
 
 	fn transfer() -> Weight {
-		<SelfWeightOf<T>>::transfer()
+		max_weight_of!(
+			transfer_normal(),
+			transfer_creating(),
+			transfer_removing(),
+			transfer_creating_removing()
+		)
 	}
 
 	fn approve() -> Weight {
@@ -37,11 +51,16 @@
 	}
 
 	fn transfer_from() -> Weight {
-		<SelfWeightOf<T>>::transfer_from()
+		max_weight_of!(
+			transfer_from_normal(),
+			transfer_from_creating(),
+			transfer_from_removing(),
+			transfer_from_creating_removing()
+		)
 	}
 
-	fn set_variable_metadata(_bytes: u32) -> Weight {
-		<SelfWeightOf<T>>::set_variable_metadata()
+	fn set_variable_metadata(bytes: u32) -> Weight {
+		<SelfWeightOf<T>>::set_variable_metadata(bytes)
 	}
 }
 
@@ -72,7 +91,7 @@
 	) -> DispatchResultWithPostInfo {
 		with_weight(
 			<Pallet<T>>::create_item(self, &sender, map_create_data(data, &to)?),
-			<SelfWeightOf<T>>::create_item(),
+			<CommonWeights<T>>::create_item(),
 		)
 	}
 
@@ -90,7 +109,7 @@
 		let amount = data.len();
 		with_weight(
 			<Pallet<T>>::create_multiple_items(self, &sender, data),
-			<SelfWeightOf<T>>::create_multiple_items(amount as u32),
+			<CommonWeights<T>>::create_multiple_items(amount as u32),
 		)
 	}
 
@@ -102,7 +121,7 @@
 	) -> DispatchResultWithPostInfo {
 		with_weight(
 			<Pallet<T>>::burn(self, &sender, token, amount),
-			<SelfWeightOf<T>>::burn_item(),
+			<CommonWeights<T>>::burn_item(),
 		)
 	}
 
@@ -115,7 +134,7 @@
 	) -> DispatchResultWithPostInfo {
 		with_weight(
 			<Pallet<T>>::transfer(&self, &from, &to, token, amount),
-			<SelfWeightOf<T>>::transfer(),
+			<CommonWeights<T>>::transfer(),
 		)
 	}
 
@@ -128,7 +147,7 @@
 	) -> DispatchResultWithPostInfo {
 		with_weight(
 			<Pallet<T>>::set_allowance(&self, &sender, &spender, token, amount),
-			<SelfWeightOf<T>>::approve(),
+			<CommonWeights<T>>::approve(),
 		)
 	}
 
@@ -142,7 +161,7 @@
 	) -> DispatchResultWithPostInfo {
 		with_weight(
 			<Pallet<T>>::transfer_from(&self, &sender, &from, &to, token, amount),
-			<SelfWeightOf<T>>::approve(),
+			<CommonWeights<T>>::approve(),
 		)
 	}
 
@@ -152,9 +171,10 @@
 		token: TokenId,
 		data: Vec<u8>,
 	) -> DispatchResultWithPostInfo {
+		let len = data.len();
 		with_weight(
 			<Pallet<T>>::set_variable_metadata(&self, &sender, token, data),
-			<SelfWeightOf<T>>::set_variable_metadata(),
+			<CommonWeights<T>>::set_variable_metadata(len as u32),
 		)
 	}
 
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -14,6 +14,7 @@
 use codec::{Encode, Decode};
 
 pub use pallet::*;
+#[cfg(feature = "runtime-benchmarks")]
 pub mod benchmarking;
 pub mod common;
 pub mod erc;
modifiedpallets/refungible/src/weights.rsdiffbeforeafterboth
--- a/pallets/refungible/src/weights.rs
+++ b/pallets/refungible/src/weights.rs
@@ -1,3 +1,27 @@
+// Template adopted from https://github.com/paritytech/substrate/blob/master/.maintain/frame-weight-template.hbs
+
+//! Autogenerated weights for pallet_refungible
+//!
+//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
+//! DATE: 2021-10-21, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
+//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 128
+
+// Executed Command:
+// target/release/nft
+// benchmark
+// --pallet
+// pallet-refungible
+// --wasm-execution
+// compiled
+// --extrinsic
+// *
+// --template
+// .maintain/frame-weight-template.hbs
+// --steps=50
+// --repeat=20
+// --output=./pallets/refungible/src/weights.rs
+
+
 #![cfg_attr(rustfmt, rustfmt_skip)]
 #![allow(unused_parens)]
 #![allow(unused_imports)]
@@ -5,33 +29,273 @@
 use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
 use sp_std::marker::PhantomData;
 
+/// Weight functions needed for pallet_refungible.
 pub trait WeightInfo {
 	fn create_item() -> Weight;
-	fn create_multiple_items(b: u32) -> Weight;
-	fn burn_item() -> Weight;
-	fn transfer() -> Weight;
+	fn create_multiple_items(b: u32, ) -> Weight;
+	fn burn_item_partial() -> Weight;
+	fn burn_item_fully() -> Weight;
+	fn transfer_normal() -> Weight;
+	fn transfer_creating() -> Weight;
+	fn transfer_removing() -> Weight;
+	fn transfer_creating_removing() -> Weight;
 	fn approve() -> Weight;
-	fn transfer_from() -> Weight;
-	fn set_variable_metadata() -> Weight;
+	fn transfer_from_normal() -> Weight;
+	fn transfer_from_creating() -> Weight;
+	fn transfer_from_removing() -> Weight;
+	fn transfer_from_creating_removing() -> Weight;
+	fn set_variable_metadata(b: u32, ) -> Weight;
 }
 
+/// Weights for pallet_refungible using the Substrate node and recommended hardware.
 pub struct SubstrateWeight<T>(PhantomData<T>);
 impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
-    fn create_item() -> Weight {0}
-	fn create_multiple_items(_b: u32) -> Weight {0}
-	fn burn_item() -> Weight {0}
-	fn transfer() -> Weight {0}
-	fn approve() -> Weight {0}
-	fn transfer_from() -> Weight {0}
-	fn set_variable_metadata() -> Weight {0}
+	// Storage: Refungible TokensMinted (r:1 w:1)
+	// Storage: Refungible AccountBalance (r:1 w:1)
+	// Storage: Refungible Balance (r:0 w:1)
+	// Storage: Refungible TotalSupply (r:0 w:1)
+	// Storage: Refungible TokenData (r:0 w:1)
+	// Storage: Refungible Owned (r:0 w:1)
+	fn create_item() -> Weight {
+		(18_681_000 as Weight)
+			.saturating_add(T::DbWeight::get().reads(2 as Weight))
+			.saturating_add(T::DbWeight::get().writes(6 as Weight))
+	}
+	// Storage: Refungible TokensMinted (r:1 w:1)
+	// Storage: Refungible AccountBalance (r:1 w:1)
+	// Storage: Refungible Balance (r:0 w:4)
+	// Storage: Refungible TotalSupply (r:0 w:4)
+	// Storage: Refungible TokenData (r:0 w:4)
+	// Storage: Refungible Owned (r:0 w:4)
+	fn create_multiple_items(b: u32, ) -> Weight {
+		(13_869_000 as Weight)
+			// Standard Error: 28_000
+			.saturating_add((5_611_000 as Weight).saturating_mul(b as Weight))
+			.saturating_add(T::DbWeight::get().reads(2 as Weight))
+			.saturating_add(T::DbWeight::get().writes(2 as Weight))
+			.saturating_add(T::DbWeight::get().writes((4 as Weight).saturating_mul(b as Weight)))
+	}
+	// Storage: Refungible TotalSupply (r:1 w:1)
+	// Storage: Refungible Balance (r:1 w:1)
+	// Storage: Refungible AccountBalance (r:1 w:1)
+	// Storage: Refungible Owned (r:0 w:1)
+	fn burn_item_partial() -> Weight {
+		(21_591_000 as Weight)
+			.saturating_add(T::DbWeight::get().reads(3 as Weight))
+			.saturating_add(T::DbWeight::get().writes(4 as Weight))
+	}
+	// Storage: Refungible TotalSupply (r:1 w:1)
+	// Storage: Refungible Balance (r:1 w:1)
+	// Storage: Refungible AccountBalance (r:1 w:1)
+	// Storage: Refungible TokensBurnt (r:1 w:1)
+	// Storage: Refungible TokenData (r:0 w:1)
+	// Storage: Refungible Owned (r:0 w:1)
+	fn burn_item_fully() -> Weight {
+		(29_257_000 as Weight)
+			.saturating_add(T::DbWeight::get().reads(4 as Weight))
+			.saturating_add(T::DbWeight::get().writes(6 as Weight))
+	}
+	// Storage: Refungible Balance (r:2 w:2)
+	fn transfer_normal() -> Weight {
+		(17_733_000 as Weight)
+			.saturating_add(T::DbWeight::get().reads(2 as Weight))
+			.saturating_add(T::DbWeight::get().writes(2 as Weight))
+	}
+	// Storage: Refungible Balance (r:2 w:2)
+	// Storage: Refungible AccountBalance (r:1 w:1)
+	// Storage: Refungible Owned (r:0 w:1)
+	fn transfer_creating() -> Weight {
+		(20_943_000 as Weight)
+			.saturating_add(T::DbWeight::get().reads(3 as Weight))
+			.saturating_add(T::DbWeight::get().writes(4 as Weight))
+	}
+	// Storage: Refungible Balance (r:2 w:2)
+	// Storage: Refungible AccountBalance (r:1 w:1)
+	// Storage: Refungible Owned (r:0 w:1)
+	fn transfer_removing() -> Weight {
+		(22_406_000 as Weight)
+			.saturating_add(T::DbWeight::get().reads(3 as Weight))
+			.saturating_add(T::DbWeight::get().writes(4 as Weight))
+	}
+	// Storage: Refungible Balance (r:2 w:2)
+	// Storage: Refungible AccountBalance (r:2 w:2)
+	// Storage: Refungible Owned (r:0 w:2)
+	fn transfer_creating_removing() -> Weight {
+		(24_762_000 as Weight)
+			.saturating_add(T::DbWeight::get().reads(4 as Weight))
+			.saturating_add(T::DbWeight::get().writes(6 as Weight))
+	}
+	// Storage: Refungible Balance (r:1 w:0)
+	// Storage: Refungible Allowance (r:0 w:1)
+	fn approve() -> Weight {
+		(14_109_000 as Weight)
+			.saturating_add(T::DbWeight::get().reads(1 as Weight))
+			.saturating_add(T::DbWeight::get().writes(1 as Weight))
+	}
+	// Storage: Refungible Allowance (r:1 w:1)
+	// Storage: Refungible Balance (r:2 w:2)
+	fn transfer_from_normal() -> Weight {
+		(25_348_000 as Weight)
+			.saturating_add(T::DbWeight::get().reads(3 as Weight))
+			.saturating_add(T::DbWeight::get().writes(3 as Weight))
+	}
+	// Storage: Refungible Allowance (r:1 w:1)
+	// Storage: Refungible Balance (r:2 w:2)
+	// Storage: Refungible AccountBalance (r:1 w:1)
+	// Storage: Refungible Owned (r:0 w:1)
+	fn transfer_from_creating() -> Weight {
+		(28_647_000 as Weight)
+			.saturating_add(T::DbWeight::get().reads(4 as Weight))
+			.saturating_add(T::DbWeight::get().writes(5 as Weight))
+	}
+	// Storage: Refungible Allowance (r:1 w:1)
+	// Storage: Refungible Balance (r:2 w:2)
+	// Storage: Refungible AccountBalance (r:1 w:1)
+	// Storage: Refungible Owned (r:0 w:1)
+	fn transfer_from_removing() -> Weight {
+		(30_472_000 as Weight)
+			.saturating_add(T::DbWeight::get().reads(4 as Weight))
+			.saturating_add(T::DbWeight::get().writes(5 as Weight))
+	}
+	// Storage: Refungible Allowance (r:1 w:1)
+	// Storage: Refungible Balance (r:2 w:2)
+	// Storage: Refungible AccountBalance (r:2 w:2)
+	// Storage: Refungible Owned (r:0 w:2)
+	fn transfer_from_creating_removing() -> Weight {
+		(32_362_000 as Weight)
+			.saturating_add(T::DbWeight::get().reads(5 as Weight))
+			.saturating_add(T::DbWeight::get().writes(7 as Weight))
+	}
+	// Storage: Refungible TokenData (r:1 w:1)
+	fn set_variable_metadata(_b: u32, ) -> Weight {
+		(6_801_000 as Weight)
+			.saturating_add(T::DbWeight::get().reads(1 as Weight))
+			.saturating_add(T::DbWeight::get().writes(1 as Weight))
+	}
 }
 
+// For backwards compatibility and tests
 impl WeightInfo for () {
-    fn create_item() -> Weight {0}
-	fn create_multiple_items(_b: u32) -> Weight {0}
-	fn burn_item() -> Weight {0}
-	fn transfer() -> Weight {0}
-	fn approve() -> Weight {0}
-	fn transfer_from() -> Weight {0}
-	fn set_variable_metadata() -> Weight {0}
+	// Storage: Refungible TokensMinted (r:1 w:1)
+	// Storage: Refungible AccountBalance (r:1 w:1)
+	// Storage: Refungible Balance (r:0 w:1)
+	// Storage: Refungible TotalSupply (r:0 w:1)
+	// Storage: Refungible TokenData (r:0 w:1)
+	// Storage: Refungible Owned (r:0 w:1)
+	fn create_item() -> Weight {
+		(18_681_000 as Weight)
+			.saturating_add(RocksDbWeight::get().reads(2 as Weight))
+			.saturating_add(RocksDbWeight::get().writes(6 as Weight))
+	}
+	// Storage: Refungible TokensMinted (r:1 w:1)
+	// Storage: Refungible AccountBalance (r:1 w:1)
+	// Storage: Refungible Balance (r:0 w:4)
+	// Storage: Refungible TotalSupply (r:0 w:4)
+	// Storage: Refungible TokenData (r:0 w:4)
+	// Storage: Refungible Owned (r:0 w:4)
+	fn create_multiple_items(b: u32, ) -> Weight {
+		(13_869_000 as Weight)
+			// Standard Error: 28_000
+			.saturating_add((5_611_000 as Weight).saturating_mul(b as Weight))
+			.saturating_add(RocksDbWeight::get().reads(2 as Weight))
+			.saturating_add(RocksDbWeight::get().writes(2 as Weight))
+			.saturating_add(RocksDbWeight::get().writes((4 as Weight).saturating_mul(b as Weight)))
+	}
+	// Storage: Refungible TotalSupply (r:1 w:1)
+	// Storage: Refungible Balance (r:1 w:1)
+	// Storage: Refungible AccountBalance (r:1 w:1)
+	// Storage: Refungible Owned (r:0 w:1)
+	fn burn_item_partial() -> Weight {
+		(21_591_000 as Weight)
+			.saturating_add(RocksDbWeight::get().reads(3 as Weight))
+			.saturating_add(RocksDbWeight::get().writes(4 as Weight))
+	}
+	// Storage: Refungible TotalSupply (r:1 w:1)
+	// Storage: Refungible Balance (r:1 w:1)
+	// Storage: Refungible AccountBalance (r:1 w:1)
+	// Storage: Refungible TokensBurnt (r:1 w:1)
+	// Storage: Refungible TokenData (r:0 w:1)
+	// Storage: Refungible Owned (r:0 w:1)
+	fn burn_item_fully() -> Weight {
+		(29_257_000 as Weight)
+			.saturating_add(RocksDbWeight::get().reads(4 as Weight))
+			.saturating_add(RocksDbWeight::get().writes(6 as Weight))
+	}
+	// Storage: Refungible Balance (r:2 w:2)
+	fn transfer_normal() -> Weight {
+		(17_733_000 as Weight)
+			.saturating_add(RocksDbWeight::get().reads(2 as Weight))
+			.saturating_add(RocksDbWeight::get().writes(2 as Weight))
+	}
+	// Storage: Refungible Balance (r:2 w:2)
+	// Storage: Refungible AccountBalance (r:1 w:1)
+	// Storage: Refungible Owned (r:0 w:1)
+	fn transfer_creating() -> Weight {
+		(20_943_000 as Weight)
+			.saturating_add(RocksDbWeight::get().reads(3 as Weight))
+			.saturating_add(RocksDbWeight::get().writes(4 as Weight))
+	}
+	// Storage: Refungible Balance (r:2 w:2)
+	// Storage: Refungible AccountBalance (r:1 w:1)
+	// Storage: Refungible Owned (r:0 w:1)
+	fn transfer_removing() -> Weight {
+		(22_406_000 as Weight)
+			.saturating_add(RocksDbWeight::get().reads(3 as Weight))
+			.saturating_add(RocksDbWeight::get().writes(4 as Weight))
+	}
+	// Storage: Refungible Balance (r:2 w:2)
+	// Storage: Refungible AccountBalance (r:2 w:2)
+	// Storage: Refungible Owned (r:0 w:2)
+	fn transfer_creating_removing() -> Weight {
+		(24_762_000 as Weight)
+			.saturating_add(RocksDbWeight::get().reads(4 as Weight))
+			.saturating_add(RocksDbWeight::get().writes(6 as Weight))
+	}
+	// Storage: Refungible Balance (r:1 w:0)
+	// Storage: Refungible Allowance (r:0 w:1)
+	fn approve() -> Weight {
+		(14_109_000 as Weight)
+			.saturating_add(RocksDbWeight::get().reads(1 as Weight))
+			.saturating_add(RocksDbWeight::get().writes(1 as Weight))
+	}
+	// Storage: Refungible Allowance (r:1 w:1)
+	// Storage: Refungible Balance (r:2 w:2)
+	fn transfer_from_normal() -> Weight {
+		(25_348_000 as Weight)
+			.saturating_add(RocksDbWeight::get().reads(3 as Weight))
+			.saturating_add(RocksDbWeight::get().writes(3 as Weight))
+	}
+	// Storage: Refungible Allowance (r:1 w:1)
+	// Storage: Refungible Balance (r:2 w:2)
+	// Storage: Refungible AccountBalance (r:1 w:1)
+	// Storage: Refungible Owned (r:0 w:1)
+	fn transfer_from_creating() -> Weight {
+		(28_647_000 as Weight)
+			.saturating_add(RocksDbWeight::get().reads(4 as Weight))
+			.saturating_add(RocksDbWeight::get().writes(5 as Weight))
+	}
+	// Storage: Refungible Allowance (r:1 w:1)
+	// Storage: Refungible Balance (r:2 w:2)
+	// Storage: Refungible AccountBalance (r:1 w:1)
+	// Storage: Refungible Owned (r:0 w:1)
+	fn transfer_from_removing() -> Weight {
+		(30_472_000 as Weight)
+			.saturating_add(RocksDbWeight::get().reads(4 as Weight))
+			.saturating_add(RocksDbWeight::get().writes(5 as Weight))
+	}
+	// Storage: Refungible Allowance (r:1 w:1)
+	// Storage: Refungible Balance (r:2 w:2)
+	// Storage: Refungible AccountBalance (r:2 w:2)
+	// Storage: Refungible Owned (r:0 w:2)
+	fn transfer_from_creating_removing() -> Weight {
+		(32_362_000 as Weight)
+			.saturating_add(RocksDbWeight::get().reads(5 as Weight))
+			.saturating_add(RocksDbWeight::get().writes(7 as Weight))
+	}
+	// Storage: Refungible TokenData (r:1 w:1)
+	fn set_variable_metadata(_b: u32, ) -> Weight {
+		(6_801_000 as Weight)
+			.saturating_add(RocksDbWeight::get().reads(1 as Weight))
+			.saturating_add(RocksDbWeight::get().writes(1 as Weight))
+	}
 }