Skip to content

Commit

Permalink
department-funding benchmarking create_department_required_fund
Browse files Browse the repository at this point in the history
  • Loading branch information
amiyatulu committed Oct 9, 2024
1 parent ea34a62 commit db96b68
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 102 deletions.
58 changes: 43 additions & 15 deletions custom-pallets/department-funding/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,60 @@
use super::*;

#[allow(unused)]
use crate::Pallet as Template;
use crate::Pallet as DepartmentFunding;
use frame_benchmarking::v2::*;
use frame_system::RawOrigin;
use pallet_support::Content;
const SEED: u32 = 0;
use frame_support::{assert_noop, assert_ok};

#[benchmarks(
where T: pallet_departments::Config + frame_system::Config
)]
#[benchmarks]
mod benchmarks {
use super::*;

#[benchmark]
fn do_something() {
let value = 100u32.into();
let caller: T::AccountId = whitelisted_caller();
#[extrinsic_call]
do_something(RawOrigin::Signed(caller), value);
fn create_department_required_fund() {
let account_id = 1;
let department_id = 1;
let tipping_name = TippingName::SmallTipper;

assert_eq!(Something::<T>::get(), Some(value));
}
let account1 = account::<T::AccountId>("account1", 1, SEED);

#[benchmark]
fn cause_error() {
Something::<T>::put(100u32);
let caller: T::AccountId = whitelisted_caller();
#[extrinsic_call]
cause_error(RawOrigin::Signed(caller));
let balance = DepartmentFunding::<T>::u64_to_balance_saturated(100000000000000);

let _ = <T as pallet::Config>::Currency::deposit_creating(&account1, balance);

assert_eq!(Something::<T>::get(), Some(101u32));
let funding_needed = DepartmentFunding::<T>::u64_to_balance_saturated(10_000u64);
// Dispatch a signed extrinsic.
let department_account_id = 5;
let content_department: Content = Content::IPFS(
"bafkreiaiq24be2iioasr6ftyaum3icmj7amtjkom2jeokov5k5ojwzhvqy"
.as_bytes()
.to_vec(),
);

assert_ok!(<pallet_departments::Pallet<T>>::create_department(
RawOrigin::Signed(account1.clone()).into(),
content_department
));

let content: Content = Content::IPFS(
"bafkreiaiq24be2iioasr6ftyaum3icmj7amtjkom2jeokov5k5ojwzhvqy"
.as_bytes()
.to_vec(),
);

#[extrinsic_call]
create_department_required_fund(
RawOrigin::Signed(account1),
department_id,
content.clone(),
tipping_name,
funding_needed,
);
}

impl_benchmark_test_suite!(Template, crate::mock::new_test_ext(), crate::mock::Test);
Expand Down
4 changes: 2 additions & 2 deletions custom-pallets/department-funding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ mod mock;
#[cfg(test)]
mod tests;

// #[cfg(feature = "runtime-benchmarks")]
// mod benchmarking;
#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
pub mod weights;
pub use weights::*;

Expand Down
111 changes: 54 additions & 57 deletions custom-pallets/department-funding/src/weights.rs
Original file line number Diff line number Diff line change
@@ -1,91 +1,88 @@

//! Autogenerated weights for pallet_template
//! Autogenerated weights for `pallet_department_funding`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-04-06, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2024-10-09, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `Alexs-MacBook-Pro-2.local`, CPU: `<UNKNOWN>`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
//! HOSTNAME: `amiya`, CPU: `12th Gen Intel(R) Core(TM) i7-12650H`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024`
// Executed Command:
// ../../target/release/node-template
// target/release/node-template
// benchmark
// pallet
// --chain
// dev
// --wasm-execution
// compiled
// --pallet
// pallet_template
// pallet-department-funding
// --extrinsic
// *
// --steps=50
// --repeat=20
// --execution=wasm
// --wasm-execution=compiled
// --steps
// 50
// --repeat
// 20
// --output
// pallets/template/src/weights.rs
// --template
// ../../.maintain/frame-weight-template.hbs
// custom-pallets/department-funding/src/weights.rs
// --template=./.maintain/frame-weight-template.hbs

#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(missing_docs)]

use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use core::marker::PhantomData;

/// Weight functions needed for pallet_template.
/// Weight functions needed for `pallet_department_funding`.
pub trait WeightInfo {
fn do_something() -> Weight;
fn cause_error() -> Weight;
fn create_department_required_fund() -> Weight;
}

/// Weights for pallet_template using the Substrate node and recommended hardware.
/// Weights for `pallet_department_funding` using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Storage: TemplateModule Something (r:0 w:1)
/// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
fn do_something() -> Weight {
/// Storage: `Departments::Departments` (r:1 w:0)
/// Proof: `Departments::Departments` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `DepartmentFunding::NextDepartmentRequiredFundId` (r:1 w:1)
/// Proof: `DepartmentFunding::NextDepartmentRequiredFundId` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `Timestamp::Now` (r:1 w:0)
/// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:1 w:1)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `DepartmentFunding::DepartmentRequiredFunds` (r:0 w:1)
/// Proof: `DepartmentFunding::DepartmentRequiredFunds` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn create_department_required_fund() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 8_000_000 picoseconds.
Weight::from_parts(9_000_000, 0)
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: TemplateModule Something (r:1 w:1)
/// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
fn cause_error() -> Weight {
// Proof Size summary in bytes:
// Measured: `32`
// Estimated: `1489`
// Minimum execution time: 6_000_000 picoseconds.
Weight::from_parts(6_000_000, 1489)
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
// Measured: `345`
// Estimated: `3810`
// Minimum execution time: 26_415_000 picoseconds.
Weight::from_parts(27_367_000, 3810)
.saturating_add(T::DbWeight::get().reads(4_u64))
.saturating_add(T::DbWeight::get().writes(3_u64))
}
}

// For backwards compatibility and tests
// For backwards compatibility and tests.
impl WeightInfo for () {
/// Storage: TemplateModule Something (r:0 w:1)
/// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
fn do_something() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 8_000_000 picoseconds.
Weight::from_parts(9_000_000, 0)
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
/// Storage: TemplateModule Something (r:1 w:1)
/// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
fn cause_error() -> Weight {
/// Storage: `Departments::Departments` (r:1 w:0)
/// Proof: `Departments::Departments` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `DepartmentFunding::NextDepartmentRequiredFundId` (r:1 w:1)
/// Proof: `DepartmentFunding::NextDepartmentRequiredFundId` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `Timestamp::Now` (r:1 w:0)
/// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:1 w:1)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `DepartmentFunding::DepartmentRequiredFunds` (r:0 w:1)
/// Proof: `DepartmentFunding::DepartmentRequiredFunds` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn create_department_required_fund() -> Weight {
// Proof Size summary in bytes:
// Measured: `32`
// Estimated: `1489`
// Minimum execution time: 6_000_000 picoseconds.
Weight::from_parts(6_000_000, 1489)
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
// Measured: `345`
// Estimated: `3810`
// Minimum execution time: 26_415_000 picoseconds.
Weight::from_parts(27_367_000, 3810)
.saturating_add(RocksDbWeight::get().reads(4_u64))
.saturating_add(RocksDbWeight::get().writes(3_u64))
}
}
28 changes: 0 additions & 28 deletions custom-pallets/positive-externality/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,33 +609,5 @@ pub mod pallet {
}
Ok(())
}

// #[pallet::call_index(9)]
// #[pallet::weight(0)]
// pub fn get_incentives(
// origin: OriginFor<T>,
// user_to_calculate: T::AccountId,
// ) -> DispatchResult {
// let _who = ensure_signed(origin)?;
// let pe_block_number = <ValidationBlock<T>>::get(user_to_calculate.clone());

// let key = SumTreeName::PositiveExternality {
// user_address: user_to_calculate.clone(),
// block_number: pe_block_number.clone(),
// };

// let phase_data = Self::get_phase_data();
// T::SchellingGameSharedSource::get_incentives_score_schelling_helper_link(
// key.clone(),
// phase_data,
// RangePoint::ZeroToFive,
// )?;

// let score = T::SchellingGameSharedSource::get_mean_value_link(key.clone())?;
// // println!("Score {:?}", score);
// T::SharedStorageSource::set_positive_externality_link(user_to_calculate, score)?;

// Ok(())
// }
}
}
10 changes: 10 additions & 0 deletions notes
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ cargo run --release --features runtime-benchmarks -- benchmark pallet \
--repeat 20 \
--output custom-pallets/positive-externality/src/weights.rs --template=./.maintain/frame-weight-template.hbs


cargo run --release --features runtime-benchmarks -- benchmark pallet \
--chain dev \
--wasm-execution compiled \
--pallet "pallet-department-funding" \
--extrinsic "*" \
--steps 50 \
--repeat 20 \
--output custom-pallets/department-funding/src/weights.rs --template=./.maintain/frame-weight-template.hbs



cargo run --release --features runtime-benchmarks -- benchmark pallet \
Expand Down
1 change: 1 addition & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ mod benches {
[pallet_template, TemplateModule]
[pallet_project_tips, ProjectTips]
[pallet_positive_externality, PositiveExternality]
[pallet_department_funding, DepartmentFunding]
);
}

Expand Down

0 comments on commit db96b68

Please sign in to comment.