From 8b21d7844b51c23a444005949dfc5de948e66a63 Mon Sep 17 00:00:00 2001 From: Erick Casanova Date: Mon, 28 Nov 2022 14:26:51 -0600 Subject: [PATCH 1/7] update benchmarking in fruniques --- pallets/fruniques/src/benchmarking.rs | 63 +++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/pallets/fruniques/src/benchmarking.rs b/pallets/fruniques/src/benchmarking.rs index d496a9fc..586b9993 100644 --- a/pallets/fruniques/src/benchmarking.rs +++ b/pallets/fruniques/src/benchmarking.rs @@ -1,11 +1,66 @@ //! Benchmarking setup for pallet-template +#![cfg(feature = "runtime-benchmarks")] use super::*; +use frame_benchmarking::{ + account, benchmarks_instance_pallet, whitelist_account, whitelisted_caller, +}; -#[allow(unused)] -use crate::Pallet as Template; -use frame_benchmarking::{benchmarks, whitelisted_caller}; -use frame_system::RawOrigin; +use frame_support::{ + dispatch::UnfilteredDispatchable, + traits::{EnsureOrigin, Get}, + BoundedVec, +}; + +use frame_system::RawOrigin as SystemOrigin; +use sp_runtime::traits::Bounded; +use sp_std::prelude::*; + +use crate::Pallet as Fruniques; + +fn dummy_description() -> BoundedVec { + BoundedVec::::try_from(b"dummy description".to_vec()).unwrap() +} + +fn dummy_attributes() -> Vec<(BoundedVec, BoundedVec)> { + vec![( + BoundedVec::::try_from(b"dummy key".encode()) + .expect("Error on encoding key to BoundedVec"), + BoundedVec::::try_from(b"dummy value".encode()) + .expect("Error on encoding value to BoundedVec"), + )] +} + +fn dummy_empty_attributes() -> Vec<(BoundedVec, BoundedVec)> { + vec![] +} + +fn create_collection( +) -> (T::AccountId, AccountIdLookupOf, T::CollectionDescription) { + let caller: T::AccountId = whitelisted_caller(); + let caller_lookup = T::Lookup::unlookup(caller.clone()); + let collection_description = dummy_description(); + assert!(Fruniques::::create_collection( + SystemOrigin::Signed(caller.clone()).into(), + collection_description.clone(), + ) + .is_ok()); + (caller, caller_lookup, collection_description) +} + +fn spawn( +) -> (T::AccountId, AccountIdLookupOf, T::CollectionDescription, Attributes, Some(HierarchicalInfo)) { + let caller: T::AccountId = whitelisted_caller(); + let caller_lookup = T::Lookup::unlookup(caller.clone()); + let collection_description = dummy_description(); + + assert!(Fruniques::::create_collection( + SystemOrigin::Signed(caller.clone()).into(), + collection_description.clone(), + ) + .is_ok()); + (caller, caller_lookup, collection_description) +} benchmarks! { do_something { From 20640d0ca8105c7cea18878d14d8fd0848289b08 Mon Sep 17 00:00:00 2001 From: Erick Casanova Date: Mon, 28 Nov 2022 14:27:53 -0600 Subject: [PATCH 2/7] update --- pallets/fruniques/src/benchmarking.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/pallets/fruniques/src/benchmarking.rs b/pallets/fruniques/src/benchmarking.rs index 586b9993..1e565775 100644 --- a/pallets/fruniques/src/benchmarking.rs +++ b/pallets/fruniques/src/benchmarking.rs @@ -53,13 +53,7 @@ fn spawn( let caller: T::AccountId = whitelisted_caller(); let caller_lookup = T::Lookup::unlookup(caller.clone()); let collection_description = dummy_description(); - - assert!(Fruniques::::create_collection( - SystemOrigin::Signed(caller.clone()).into(), - collection_description.clone(), - ) - .is_ok()); - (caller, caller_lookup, collection_description) + let attributes = dummy_attributes(); } benchmarks! { From b8e8bf3883f069bd5d7ace163286b8552ac2d23a Mon Sep 17 00:00:00 2001 From: Erick Casanova Date: Wed, 30 Nov 2022 12:59:14 -0600 Subject: [PATCH 3/7] delete unused Helper --- runtime/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 065621b9..9f1feda1 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -538,7 +538,6 @@ impl pallet_uniques::Config for Runtime { type ValueLimit = ValueLimit; type WeightInfo = pallet_uniques::weights::SubstrateWeight; #[cfg(feature = "runtime-benchmarks")] - type Helper = (); type CreateOrigin = AsEnsureOriginWithArg>; type Locker = (); } From 52580d94d6c0cc616e85f2921233e4ca0ac60f22 Mon Sep 17 00:00:00 2001 From: Erick Casanova Date: Wed, 30 Nov 2022 13:00:59 -0600 Subject: [PATCH 4/7] add weights for the template pallet --- pallets/template/src/weights.rs | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 pallets/template/src/weights.rs diff --git a/pallets/template/src/weights.rs b/pallets/template/src/weights.rs new file mode 100644 index 00000000..b3daf7ed --- /dev/null +++ b/pallets/template/src/weights.rs @@ -0,0 +1,42 @@ + +//! Autogenerated weights for `pallet_template` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-11-30, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `hashed`, CPU: `11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz` +//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/release/hashed +// benchmark +// pallet +// --chain +// dev +// --pallet +// pallet_template +// --extrinsic +// * +// --steps +// 20 +// --repeat +// 10 +// --output +// pallets/template/src/weights.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for `pallet_template`. +pub struct WeightInfo(PhantomData); +impl pallet_template::WeightInfo for WeightInfo { + // Storage: TemplateModule Something (r:0 w:1) + /// The range of component `s` is `[0, 100]`. + fn do_something(_s: u32, ) -> Weight { + (13_467_000 as Weight) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } +} From 7e4b3b2ea5c32f71fb129d873b03f121b5d729a8 Mon Sep 17 00:00:00 2001 From: Erick Casanova Date: Wed, 30 Nov 2022 14:09:42 -0600 Subject: [PATCH 5/7] Add weights for the template This commit add weights for the pallet template and a mock up of how to import weights on pallet calls --- .maintain/frame-weight-template.hbs | 107 ++++++++++++++++++++++++++++ Cargo.lock | 1 + HEADER-APACHE2 | 16 +++++ pallets/template/Cargo.toml | 3 + pallets/template/src/lib.rs | 8 ++- pallets/template/src/mock.rs | 1 + pallets/template/src/weights.rs | 66 +++++++++++++---- runtime/src/lib.rs | 20 +++++- 8 files changed, 206 insertions(+), 16 deletions(-) create mode 100644 .maintain/frame-weight-template.hbs create mode 100644 HEADER-APACHE2 diff --git a/.maintain/frame-weight-template.hbs b/.maintain/frame-weight-template.hbs new file mode 100644 index 00000000..9c9e2978 --- /dev/null +++ b/.maintain/frame-weight-template.hbs @@ -0,0 +1,107 @@ +{{header}} +//! Autogenerated weights for {{pallet}} +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION {{version}} +//! DATE: {{date}}, STEPS: `{{cmd.steps}}`, REPEAT: {{cmd.repeat}}, LOW RANGE: `{{cmd.lowest_range_values}}`, HIGH RANGE: `{{cmd.highest_range_values}}` +//! HOSTNAME: `{{hostname}}`, CPU: `{{cpuname}}` +//! EXECUTION: {{cmd.execution}}, WASM-EXECUTION: {{cmd.wasm_execution}}, CHAIN: {{cmd.chain}}, DB CACHE: {{cmd.db_cache}} + +// Executed Command: +{{#each args as |arg|}} +// {{arg}} +{{/each}} + +#![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}}. +pub trait WeightInfo { + {{#each benchmarks as |benchmark|}} + fn {{benchmark.name~}} + ( + {{~#each benchmark.components as |c| ~}} + {{c.name}}: u32, {{/each~}} + ) -> Weight; + {{/each}} +} + +/// Weights for {{pallet}} using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +{{#if (eq pallet "frame_system")}} +impl WeightInfo for SubstrateWeight { +{{else}} +impl WeightInfo for SubstrateWeight { +{{/if}} + {{#each benchmarks as |benchmark|}} + {{#each benchmark.comments as |comment|}} + // {{comment}} + {{/each}} + {{#each benchmark.component_ranges as |range|}} + /// The range of component `{{range.name}}` is `[{{range.min}}, {{range.max}}]`. + {{/each}} + fn {{benchmark.name~}} + ( + {{~#each benchmark.components as |c| ~}} + {{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}} + ) -> Weight { + // Minimum execution time: {{underscore benchmark.min_execution_time}} nanoseconds. + Weight::from_ref_time({{underscore benchmark.base_weight}}) + {{#each benchmark.component_weight as |cw|}} + // Standard Error: {{underscore cw.error}} + .saturating_add(Weight::from_ref_time({{underscore cw.slope}}).saturating_mul({{cw.name}}.into())) + {{/each}} + {{#if (ne benchmark.base_reads "0")}} + .saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}})) + {{/if}} + {{#each benchmark.component_reads as |cr|}} + .saturating_add(T::DbWeight::get().reads(({{cr.slope}}_u64).saturating_mul({{cr.name}}.into()))) + {{/each}} + {{#if (ne benchmark.base_writes "0")}} + .saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}})) + {{/if}} + {{#each benchmark.component_writes as |cw|}} + .saturating_add(T::DbWeight::get().writes(({{cw.slope}}_u64).saturating_mul({{cw.name}}.into()))) + {{/each}} + } + {{/each}} +} + +// For backwards compatibility and tests +impl WeightInfo for () { + {{#each benchmarks as |benchmark|}} + {{#each benchmark.comments as |comment|}} + // {{comment}} + {{/each}} + {{#each benchmark.component_ranges as |range|}} + /// The range of component `{{range.name}}` is `[{{range.min}}, {{range.max}}]`. + {{/each}} + fn {{benchmark.name~}} + ( + {{~#each benchmark.components as |c| ~}} + {{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}} + ) -> Weight { + // Minimum execution time: {{underscore benchmark.min_execution_time}} nanoseconds. + Weight::from_ref_time({{underscore benchmark.base_weight}}) + {{#each benchmark.component_weight as |cw|}} + // Standard Error: {{underscore cw.error}} + .saturating_add(Weight::from_ref_time({{underscore cw.slope}}).saturating_mul({{cw.name}}.into())) + {{/each}} + {{#if (ne benchmark.base_reads "0")}} + .saturating_add(RocksDbWeight::get().reads({{benchmark.base_reads}})) + {{/if}} + {{#each benchmark.component_reads as |cr|}} + .saturating_add(RocksDbWeight::get().reads(({{cr.slope}}_u64).saturating_mul({{cr.name}}.into()))) + {{/each}} + {{#if (ne benchmark.base_writes "0")}} + .saturating_add(RocksDbWeight::get().writes({{benchmark.base_writes}})) + {{/if}} + {{#each benchmark.component_writes as |cw|}} + .saturating_add(RocksDbWeight::get().writes(({{cw.slope}}_u64).saturating_mul({{cw.name}}.into()))) + {{/each}} + } + {{/each}} +} diff --git a/Cargo.lock b/Cargo.lock index e9d0501e..5f282625 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6099,6 +6099,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", + "sp-std", ] [[package]] diff --git a/HEADER-APACHE2 b/HEADER-APACHE2 new file mode 100644 index 00000000..52edacd5 --- /dev/null +++ b/HEADER-APACHE2 @@ -0,0 +1,16 @@ +// This file is part of Substrate. + +// Copyright (C) 2022 Hashed Network. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. diff --git a/pallets/template/Cargo.toml b/pallets/template/Cargo.toml index a219ae6b..bd55e682 100644 --- a/pallets/template/Cargo.toml +++ b/pallets/template/Cargo.toml @@ -20,11 +20,13 @@ scale-info = { version = "2.1.1", default-features = false, features = ["derive" frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27"} frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" } frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27", optional = true } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" } [dev-dependencies] sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" } sp-io = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" } sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" } [features] default = ["std"] @@ -34,6 +36,7 @@ std = [ "frame-support/std", "frame-system/std", "frame-benchmarking/std", + "sp-std/std", ] runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"] diff --git a/pallets/template/src/lib.rs b/pallets/template/src/lib.rs index 3d11317b..752da00e 100644 --- a/pallets/template/src/lib.rs +++ b/pallets/template/src/lib.rs @@ -4,7 +4,8 @@ /// Learn more about FRAME and the core library of Substrate FRAME pallets: /// pub use pallet::*; - +pub mod weights; +pub use weights::*; #[cfg(test)] mod mock; @@ -17,6 +18,8 @@ mod benchmarking; #[frame_support::pallet] pub mod pallet { + use super::*; + use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; @@ -25,6 +28,7 @@ use frame_support::pallet_prelude::*; pub trait Config: frame_system::Config { /// Because this pallet emits events, it depends on the runtime's definition of an event. type Event: From> + IsType<::Event>; + type WeightInfo: WeightInfo; } #[pallet::pallet] @@ -72,7 +76,7 @@ use frame_support::pallet_prelude::*; impl Pallet { /// An example dispatchable that takes a singles value as a parameter, writes the value to /// storage and emits an event. This function must be dispatched by a signed extrinsic. - #[pallet::weight(10_000 + T::DbWeight::get().writes(1))] + #[pallet::weight((T::WeightInfo::do_something(100), DispatchClass::Operational))] pub fn do_something(origin: OriginFor, something: u32) -> DispatchResult { // Check that the extrinsic was signed and get the signer. // This function will return an error if the extrinsic is not signed. diff --git a/pallets/template/src/mock.rs b/pallets/template/src/mock.rs index 733ac79d..adc65b7b 100644 --- a/pallets/template/src/mock.rs +++ b/pallets/template/src/mock.rs @@ -56,6 +56,7 @@ impl system::Config for Test { impl pallet_template::Config for Test { type Event = Event; + type WeightInfo = (); } // Build genesis storage according to the mock runtime. diff --git a/pallets/template/src/weights.rs b/pallets/template/src/weights.rs index b3daf7ed..9b37772f 100644 --- a/pallets/template/src/weights.rs +++ b/pallets/template/src/weights.rs @@ -1,10 +1,26 @@ +// This file is part of Substrate. -//! Autogenerated weights for `pallet_template` +// Copyright (C) 2022 Hashed Network. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Autogenerated weights for pallet_template //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-11-30, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-11-30, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! HOSTNAME: `hashed`, CPU: `11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz` -//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: // ./target/release/hashed @@ -16,27 +32,53 @@ // pallet_template // --extrinsic // * +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 // --steps -// 20 +// 50 // --repeat -// 10 +// 20 +// --header=./HEADER-APACHE2 // --output // pallets/template/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}; +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use sp_std::marker::PhantomData; -/// Weight functions for `pallet_template`. -pub struct WeightInfo(PhantomData); -impl pallet_template::WeightInfo for WeightInfo { +/// Weight functions needed for pallet_template. +pub trait WeightInfo { + fn do_something(s: u32, ) -> Weight; +} + +/// Weights for pallet_template using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + // Storage: TemplateModule Something (r:0 w:1) + /// The range of component `s` is `[0, 100]`. + fn do_something(s: u32, ) -> Weight { + // Minimum execution time: nanoseconds. + Weight::from_ref_time(20_147_000) + // Standard Error: 2_000 + .saturating_add(Weight::from_ref_time(2_000).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().writes(1)) + } +} + +// For backwards compatibility and tests +impl WeightInfo for () { // Storage: TemplateModule Something (r:0 w:1) /// The range of component `s` is `[0, 100]`. - fn do_something(_s: u32, ) -> Weight { - (13_467_000 as Weight) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + fn do_something(s: u32, ) -> Weight { + // Minimum execution time: nanoseconds. + Weight::from_ref_time(20_147_000) + // Standard Error: 2_000 + .saturating_add(Weight::from_ref_time(2_000).saturating_mul(s.into())) + .saturating_add(RocksDbWeight::get().writes(1)) } } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 9f1feda1..7133ed38 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -263,7 +263,6 @@ impl pallet_balances::Config for Runtime { type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; - type WeightInfo = pallet_balances::weights::SubstrateWeight; } parameter_types! { @@ -331,6 +330,7 @@ impl pallet_recovery::Config for Runtime { /// Configure the pallet-template in pallets/template. impl pallet_template::Config for Runtime { type Event = Event; + type WeightInfo = pallet_template::weights::SubstrateWeight; } parameter_types! { @@ -537,7 +537,6 @@ impl pallet_uniques::Config for Runtime { type KeyLimit = KeyLimit; type ValueLimit = ValueLimit; type WeightInfo = pallet_uniques::weights::SubstrateWeight; - #[cfg(feature = "runtime-benchmarks")] type CreateOrigin = AsEnsureOriginWithArg>; type Locker = (); } @@ -825,6 +824,23 @@ pub type Executive = frame_executive::Executive< AllPalletsWithSystem, >; +#[cfg(feature = "runtime-benchmarks")] +#[macro_use] +extern crate frame_benchmarking; + +#[cfg(feature = "runtime-benchmarks")] +mod benches { + define_benchmarks!( + [frame_system, SystemBench::] + [pallet_balances, Balances] + [pallet_session, SessionBench::] + [pallet_timestamp, Timestamp] + [pallet_collator_selection, CollatorSelection] + [cumulus_pallet_xcmp_queue, XcmpQueue] + [pallet_template, Template] + ); +} + impl_runtime_apis! { impl sp_api::Core for Runtime { fn version() -> RuntimeVersion { From 45abd444c87ac2f5058d041deeeb8e6df1e9a594 Mon Sep 17 00:00:00 2001 From: Erick Casanova Date: Mon, 5 Dec 2022 13:06:07 -0600 Subject: [PATCH 6/7] add script to run the benchmark --- scripts/start_benchmarking.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100755 scripts/start_benchmarking.sh diff --git a/scripts/start_benchmarking.sh b/scripts/start_benchmarking.sh new file mode 100755 index 00000000..78ab2aaf --- /dev/null +++ b/scripts/start_benchmarking.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +echo "*** Initializing becnhmarking" + +cargo build --package node-template --release --features runtime-benchmarks + +./target/release/hashed benchmark pallet \ +--chain dev \ +--pallet pallet_template \ +--extrinsic '*' \ +--steps 20 \ +--repeat 10 \ +--output pallets/pallet-template/src/weights.rs From db74f8fd4c082538421b72dff6d63c986d7a3d81 Mon Sep 17 00:00:00 2001 From: Erick Casanova Date: Mon, 5 Dec 2022 17:23:40 -0600 Subject: [PATCH 7/7] Weights with default info --- pallets/template/src/weights.rs | 69 ++++++++------------------------- scripts/start_benchmarking.sh | 4 +- 2 files changed, 19 insertions(+), 54 deletions(-) diff --git a/pallets/template/src/weights.rs b/pallets/template/src/weights.rs index 9b37772f..dc709e72 100644 --- a/pallets/template/src/weights.rs +++ b/pallets/template/src/weights.rs @@ -1,26 +1,10 @@ -// This file is part of Substrate. -// Copyright (C) 2022 Hashed Network. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Autogenerated weights for pallet_template +//! Autogenerated weights for `pallet_template` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-11-30, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-12-05, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! HOSTNAME: `hashed`, CPU: `11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 +//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: // ./target/release/hashed @@ -32,53 +16,34 @@ // pallet_template // --extrinsic // * -// --execution=wasm -// --wasm-execution=compiled -// --heap-pages=4096 // --steps -// 50 -// --repeat // 20 -// --header=./HEADER-APACHE2 +// --repeat +// 10 // --output // pallets/template/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 frame_support::{traits::Get, weights::Weight}; use sp_std::marker::PhantomData; -/// Weight functions needed for pallet_template. -pub trait WeightInfo { - fn do_something(s: u32, ) -> Weight; -} - -/// Weights for pallet_template using the Substrate node and recommended hardware. -pub struct SubstrateWeight(PhantomData); -impl WeightInfo for SubstrateWeight { - // Storage: TemplateModule Something (r:0 w:1) - /// The range of component `s` is `[0, 100]`. - fn do_something(s: u32, ) -> Weight { - // Minimum execution time: nanoseconds. - Weight::from_ref_time(20_147_000) - // Standard Error: 2_000 - .saturating_add(Weight::from_ref_time(2_000).saturating_mul(s.into())) - .saturating_add(T::DbWeight::get().writes(1)) - } -} +// Weights functions needed for the pallet_template pallet +// pub trait WeightInfo { +// fn do_something() -> Weight; +// } -// For backwards compatibility and tests -impl WeightInfo for () { +/// Weight functions for `pallet_template`. +pub struct WeightInfo(PhantomData); +impl pallet_template::WeightInfo for WeightInfo { // Storage: TemplateModule Something (r:0 w:1) /// The range of component `s` is `[0, 100]`. fn do_something(s: u32, ) -> Weight { - // Minimum execution time: nanoseconds. - Weight::from_ref_time(20_147_000) - // Standard Error: 2_000 - .saturating_add(Weight::from_ref_time(2_000).saturating_mul(s.into())) - .saturating_add(RocksDbWeight::get().writes(1)) + (12_465_000 as Weight) + // Standard Error: 1_000 + .saturating_add((3_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) } } diff --git a/scripts/start_benchmarking.sh b/scripts/start_benchmarking.sh index 78ab2aaf..805ac4b8 100755 --- a/scripts/start_benchmarking.sh +++ b/scripts/start_benchmarking.sh @@ -4,10 +4,10 @@ echo "*** Initializing becnhmarking" cargo build --package node-template --release --features runtime-benchmarks -./target/release/hashed benchmark pallet \ +./target/release/hashed benchmark pallet \  1  6.99  100% --chain dev \ --pallet pallet_template \ --extrinsic '*' \ --steps 20 \ --repeat 10 \ ---output pallets/pallet-template/src/weights.rs +--output pallets/template/src/weights.rs