From 61bf67516c5fce6aeb4cce23dc9721aed868618f Mon Sep 17 00:00:00 2001 From: girazoki Date: Tue, 9 Apr 2024 10:25:53 +0200 Subject: [PATCH 1/2] modify benche --- .../foreign-asset-creator/src/benchmarks.rs | 50 +++++++------------ 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/pallets/foreign-asset-creator/src/benchmarks.rs b/pallets/foreign-asset-creator/src/benchmarks.rs index 8c8c356..2398b9c 100644 --- a/pallets/foreign-asset-creator/src/benchmarks.rs +++ b/pallets/foreign-asset-creator/src/benchmarks.rs @@ -37,45 +37,38 @@ benchmarks! { } change_existing_asset_type { - // We make it dependent on the number of existing assets already - let x in 5..100; const USER_SEED: u32 = 1; let manager: T::AccountId = account("manager", 0, USER_SEED); - for i in 0..x { - let foreign_asset: T::ForeignAsset = Location::new(0, [GeneralIndex(i as u128)]).into(); - let asset_id: AssetId = (i as u16).into(); - let amount = 1u32.into(); - Pallet::::create_foreign_asset( - RawOrigin::Root.into(), - foreign_asset.clone(), - asset_id.clone(), - manager.clone(), - true, - amount, - )?; - } + let foreign_asset: T::ForeignAsset = Location::new(0, [GeneralIndex(0 as u128)]).into(); + let asset_id: AssetId = (0u16).into(); + let amount = 1u32.into(); + Pallet::::create_foreign_asset( + RawOrigin::Root.into(), + foreign_asset.clone(), + asset_id.clone(), + manager.clone(), + true, + amount, + )?; let new_foreign_asset = T::ForeignAsset::default(); let asset_type_to_be_changed: T::ForeignAsset = Location::new( 0, - [GeneralIndex((x-1) as u128)] + [GeneralIndex((0) as u128)] ).into(); - let asset_id_to_be_changed: AssetId = ((x-1) as u16).into(); + let asset_id_to_be_changed: AssetId = (0u16).into(); }: _(RawOrigin::Root, asset_id_to_be_changed.clone(), new_foreign_asset.clone()) verify { assert_eq!(Pallet::::foreign_asset_for_id(asset_id_to_be_changed), Some(new_foreign_asset.clone())); } remove_existing_asset_type { - // We make it dependent on the number of existing assets already - let x in 5..100; const USER_SEED: u32 = 1; let manager: T::AccountId = account("manager", 0, USER_SEED); - for i in 0..x { - let foreign_asset: T::ForeignAsset = Location::new(0, [GeneralIndex(i as u128)]).into(); - let asset_id: AssetId = (i as u16).into(); + let foreign_asset: T::ForeignAsset = Location::new(0, [GeneralIndex(0 u128)]).into(); + let asset_id: AssetId = 0u16.into(); let amount = 1u32.into(); Pallet::::create_foreign_asset( RawOrigin::Root.into(), @@ -85,23 +78,19 @@ benchmarks! { true, amount, )?; - } - let asset_id_to_be_removed: AssetId = ((x-1) as u16).into(); + let asset_id_to_be_removed: AssetId = 0u16.into(); }: _(RawOrigin::Root, asset_id_to_be_removed.clone()) verify { assert!(Pallet::::foreign_asset_for_id(asset_id_to_be_removed).is_none()); } destroy_foreign_asset { - // We make it dependent on the number of existing assets already - let x in 5..100; const USER_SEED: u32 = 1; let manager: T::AccountId = account("manager", 0, USER_SEED); - for i in 0..x { - let foreign_asset: T::ForeignAsset = Location::new(0, [GeneralIndex(i as u128)]).into(); - let asset_id: AssetId = (i as u16).into(); + let foreign_asset: T::ForeignAsset = Location::new(0, [GeneralIndex(0u128)]).into(); + let asset_id: AssetId = 0u16.into(); let amount = 1u32.into(); Pallet::::create_foreign_asset( RawOrigin::Root.into(), @@ -111,9 +100,8 @@ benchmarks! { true, amount, )?; - } - let asset_id_to_be_destroyed: AssetId = ((x-1) as u16).into(); + let asset_id_to_be_destroyed: AssetId = 0u16.into(); }: _(RawOrigin::Root, asset_id_to_be_destroyed.clone()) verify { assert!(Pallet::::foreign_asset_for_id(asset_id_to_be_destroyed).is_none()); From fd29ab7ce6a4600b8cb013d7f8b592256d4e8513 Mon Sep 17 00:00:00 2001 From: girazoki Date: Tue, 9 Apr 2024 11:51:15 +0200 Subject: [PATCH 2/2] remove parametric benchmarking --- .../foreign-asset-creator/src/benchmarks.rs | 4 +- pallets/foreign-asset-creator/src/weights.rs | 75 +++++++++---------- 2 files changed, 37 insertions(+), 42 deletions(-) diff --git a/pallets/foreign-asset-creator/src/benchmarks.rs b/pallets/foreign-asset-creator/src/benchmarks.rs index 2398b9c..a8cd473 100644 --- a/pallets/foreign-asset-creator/src/benchmarks.rs +++ b/pallets/foreign-asset-creator/src/benchmarks.rs @@ -40,7 +40,7 @@ benchmarks! { const USER_SEED: u32 = 1; let manager: T::AccountId = account("manager", 0, USER_SEED); - let foreign_asset: T::ForeignAsset = Location::new(0, [GeneralIndex(0 as u128)]).into(); + let foreign_asset: T::ForeignAsset = Location::new(0, [GeneralIndex(0u128)]).into(); let asset_id: AssetId = (0u16).into(); let amount = 1u32.into(); Pallet::::create_foreign_asset( @@ -67,7 +67,7 @@ benchmarks! { const USER_SEED: u32 = 1; let manager: T::AccountId = account("manager", 0, USER_SEED); - let foreign_asset: T::ForeignAsset = Location::new(0, [GeneralIndex(0 u128)]).into(); + let foreign_asset: T::ForeignAsset = Location::new(0, [GeneralIndex(0u128)]).into(); let asset_id: AssetId = 0u16.into(); let amount = 1u32.into(); Pallet::::create_foreign_asset( diff --git a/pallets/foreign-asset-creator/src/weights.rs b/pallets/foreign-asset-creator/src/weights.rs index f9c784f..c9feeea 100644 --- a/pallets/foreign-asset-creator/src/weights.rs +++ b/pallets/foreign-asset-creator/src/weights.rs @@ -18,10 +18,10 @@ //! Autogenerated weights for pallet_foreign_asset_creator //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-01-09, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-04-09, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `girazoki-XPS-15-9530`, CPU: `13th Gen Intel(R) Core(TM) i9-13900H` -//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 +//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: // ./target/release/tanssi-node @@ -33,6 +33,7 @@ // pallet_foreign_asset_creator // --extrinsic // * +// --chain=dev // --steps // 50 // --repeat @@ -41,7 +42,7 @@ // --json-file // raw.json // --output -// weights.rs +// tmp/pallet_foreign_asset_creator.rs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -69,10 +70,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: `ForeignAssetsCreator::ForeignAssetToAssetId` (`max_values`: None, `max_size`: None, mode: `Measured`) fn create_foreign_asset() -> Weight { // Proof Size summary in bytes: - // Measured: `80` + // Measured: `113` // Estimated: `3673` - // Minimum execution time: 17_654_000 picoseconds. - Weight::from_parts(18_621_000, 3673) + // Minimum execution time: 16_738_000 picoseconds. + Weight::from_parts(17_366_000, 3673) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -82,11 +83,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: `ForeignAssetsCreator::ForeignAssetToAssetId` (`max_values`: None, `max_size`: None, mode: `Measured`) fn change_existing_asset_type() -> Weight { // Proof Size summary in bytes: - // Measured: `427` - // Estimated: `3880` - // Minimum execution time: 17_469_000 picoseconds. - Weight::from_parts(20_276_697, 3880) - // Standard Error: 1_876 + // Measured: `189` + // Estimated: `3654` + // Minimum execution time: 13_861_000 picoseconds. + Weight::from_parts(14_153_000, 3654) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -96,11 +96,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: `ForeignAssetsCreator::ForeignAssetToAssetId` (`max_values`: None, `max_size`: None, mode: `Measured`) fn remove_existing_asset_type() -> Weight { // Proof Size summary in bytes: - // Measured: `427` - // Estimated: `3880` - // Minimum execution time: 15_165_000 picoseconds. - Weight::from_parts(18_041_533, 3880) - // Standard Error: 1_836 + // Measured: `189` + // Estimated: `3654` + // Minimum execution time: 11_698_000 picoseconds. + Weight::from_parts(12_184_000, 3654) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -112,14 +111,13 @@ impl WeightInfo for SubstrateWeight { /// Proof: `ForeignAssetsCreator::ForeignAssetToAssetId` (`max_values`: None, `max_size`: None, mode: `Measured`) fn destroy_foreign_asset() -> Weight { // Proof Size summary in bytes: - // Measured: `981` - // Estimated: `4441` - // Minimum execution time: 22_589_000 picoseconds. - Weight::from_parts(26_897_574, 4441) - // Standard Error: 3_872 + // Measured: `429` + // Estimated: `3894` + // Minimum execution time: 17_797_000 picoseconds. + Weight::from_parts(18_635_000, 3894) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) - } + } } // For backwards compatibility and tests @@ -132,10 +130,10 @@ impl WeightInfo for () { /// Proof: `ForeignAssetsCreator::ForeignAssetToAssetId` (`max_values`: None, `max_size`: None, mode: `Measured`) fn create_foreign_asset() -> Weight { // Proof Size summary in bytes: - // Measured: `80` + // Measured: `113` // Estimated: `3673` - // Minimum execution time: 17_654_000 picoseconds. - Weight::from_parts(18_621_000, 3673) + // Minimum execution time: 16_738_000 picoseconds. + Weight::from_parts(17_366_000, 3673) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -145,11 +143,10 @@ impl WeightInfo for () { /// Proof: `ForeignAssetsCreator::ForeignAssetToAssetId` (`max_values`: None, `max_size`: None, mode: `Measured`) fn change_existing_asset_type() -> Weight { // Proof Size summary in bytes: - // Measured: `427` - // Estimated: `3880` - // Minimum execution time: 17_469_000 picoseconds. - Weight::from_parts(20_276_697, 3880) - // Standard Error: 1_876 + // Measured: `189` + // Estimated: `3654` + // Minimum execution time: 13_861_000 picoseconds. + Weight::from_parts(14_153_000, 3654) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -159,11 +156,10 @@ impl WeightInfo for () { /// Proof: `ForeignAssetsCreator::ForeignAssetToAssetId` (`max_values`: None, `max_size`: None, mode: `Measured`) fn remove_existing_asset_type() -> Weight { // Proof Size summary in bytes: - // Measured: `427` - // Estimated: `3880` - // Minimum execution time: 15_165_000 picoseconds. - Weight::from_parts(18_041_533, 3880) - // Standard Error: 1_836 + // Measured: `189` + // Estimated: `3654` + // Minimum execution time: 11_698_000 picoseconds. + Weight::from_parts(12_184_000, 3654) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -175,11 +171,10 @@ impl WeightInfo for () { /// Proof: `ForeignAssetsCreator::ForeignAssetToAssetId` (`max_values`: None, `max_size`: None, mode: `Measured`) fn destroy_foreign_asset() -> Weight { // Proof Size summary in bytes: - // Measured: `981` - // Estimated: `4441` - // Minimum execution time: 22_589_000 picoseconds. - Weight::from_parts(26_897_574, 4441) - // Standard Error: 3_872 + // Measured: `429` + // Estimated: `3894` + // Minimum execution time: 17_797_000 picoseconds. + Weight::from_parts(18_635_000, 3894) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) }