Skip to content

Commit

Permalink
draw juror positive externality benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
amiyatulu committed Oct 2, 2024
1 parent b0da115 commit 34e4569
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 21 deletions.
52 changes: 52 additions & 0 deletions custom-pallets/positive-externality/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,57 @@ mod benchmarks {
pass_period(RawOrigin::Signed(accounts[0].clone()), account1.clone());
}

#[benchmark]
fn draw_jurors() {
let account1 = account::<T::AccountId>("set-validate", 1, SEED);
assert_ok!(PositiveExternality::<T>::set_validate_positive_externality(
RawOrigin::Signed(account1.clone()).into(),
true
));
let account2 = account::<T::AccountId>("stake-account", 2, SEED);

let balance = PositiveExternality::<T>::u64_to_balance_saturated(100000000000000);

let _ = <T as pallet::Config>::Currency::deposit_creating(&account2, balance);
assert_ok!(PositiveExternality::<T>::apply_staking_period(
RawOrigin::Signed(account2.clone()).into(),
account1.clone()
));

let account3 = account::<T::AccountId>("apply-juror-account", 3, SEED);

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

let stake = PositiveExternality::<T>::u64_to_balance_saturated(100);

let mut accounts = vec![];

for j in 4..2000 {
let account_number = account::<T::AccountId>("apply-juror-account", j, SEED);
accounts.push(account_number.clone());
let _ = <T as pallet::Config>::Currency::deposit_creating(&account_number, balance);

assert_ok!(PositiveExternality::<T>::apply_jurors(
RawOrigin::Signed(account_number).into(),
account1.clone(),
(j * 100).into()
));
}

let phase_data = PositiveExternality::<T>::get_phase_data();

let now = <frame_system::Pallet<T>>::block_number();

<frame_system::Pallet<T>>::set_block_number(now + phase_data.staking_length);

assert_ok!(PositiveExternality::<T>::pass_period(
RawOrigin::Signed(accounts[0].clone()).into(),
account1.clone()
));

#[extrinsic_call]
draw_jurors(RawOrigin::Signed(accounts[1].clone()), account1.clone(), 5);
}

impl_benchmark_test_suite!(PositiveExternality, crate::mock::new_test_ext(), crate::mock::Test);
}
89 changes: 68 additions & 21 deletions custom-pallets/positive-externality/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! Autogenerated weights for `pallet_positive_externality`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2024-10-01, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2024-10-02, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `amiya`, CPU: `12th Gen Intel(R) Core(TM) i7-12650H`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024`
Expand Down Expand Up @@ -42,6 +42,7 @@ pub trait WeightInfo {
fn apply_staking_period() -> Weight;
fn apply_jurors() -> Weight;
fn pass_period() -> Weight;
fn draw_jurors() -> Weight;
}

/// Weights for `pallet_positive_externality` using the Substrate node and recommended hardware.
Expand All @@ -59,8 +60,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `12`
// Estimated: `3477`
// Minimum execution time: 7_547_000 picoseconds.
Weight::from_parts(8_012_000, 3477)
// Minimum execution time: 8_451_000 picoseconds.
Weight::from_parts(8_707_000, 3477)
.saturating_add(T::DbWeight::get().reads(3_u64))
.saturating_add(T::DbWeight::get().writes(3_u64))
}
Expand All @@ -70,8 +71,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 2_474_000 picoseconds.
Weight::from_parts(2_745_000, 0)
// Minimum execution time: 3_241_000 picoseconds.
Weight::from_parts(3_468_000, 0)
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: `PositiveExternality::Validate` (r:1 w:0)
Expand All @@ -92,8 +93,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `220`
// Estimated: `3685`
// Minimum execution time: 31_769_000 picoseconds.
Weight::from_parts(33_039_000, 3685)
// Minimum execution time: 36_598_000 picoseconds.
Weight::from_parts(37_733_000, 3685)
.saturating_add(T::DbWeight::get().reads(5_u64))
.saturating_add(T::DbWeight::get().writes(6_u64))
}
Expand All @@ -113,8 +114,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `584`
// Estimated: `4049`
// Minimum execution time: 37_109_000 picoseconds.
Weight::from_parts(38_928_000, 4049)
// Minimum execution time: 42_221_000 picoseconds.
Weight::from_parts(43_722_000, 4049)
.saturating_add(T::DbWeight::get().reads(6_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
Expand All @@ -128,11 +129,34 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `351`
// Estimated: `3816`
// Minimum execution time: 17_230_000 picoseconds.
Weight::from_parts(18_893_000, 3816)
// Minimum execution time: 21_238_000 picoseconds.
Weight::from_parts(22_268_000, 3816)
.saturating_add(T::DbWeight::get().reads(3_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: `PositiveExternality::ValidationBlock` (r:1 w:0)
/// Proof: `PositiveExternality::ValidationBlock` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `SchellingGameShared::PeriodName` (r:1 w:0)
/// Proof: `SchellingGameShared::PeriodName` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `SchellingGameShared::DrawsInRound` (r:1 w:1)
/// Proof: `SchellingGameShared::DrawsInRound` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `SchellingGameShared::Nonce` (r:1 w:1)
/// Proof: `SchellingGameShared::Nonce` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `RandomnessCollectiveFlip::RandomMaterial` (r:1 w:0)
/// Proof: `RandomnessCollectiveFlip::RandomMaterial` (`max_values`: Some(1), `max_size`: Some(2594), added: 3089, mode: `MaxEncodedLen`)
/// Storage: `SortitionSumGame::SortitionSumTrees` (r:1 w:1)
/// Proof: `SortitionSumGame::SortitionSumTrees` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `SchellingGameShared::DrawnJurors` (r:1 w:1)
/// Proof: `SchellingGameShared::DrawnJurors` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn draw_jurors() -> Weight {
// Proof Size summary in bytes:
// Measured: `184048`
// Estimated: `187513`
// Minimum execution time: 3_418_748_000 picoseconds.
Weight::from_parts(3_594_238_000, 187513)
.saturating_add(T::DbWeight::get().reads(7_u64))
.saturating_add(T::DbWeight::get().writes(4_u64))
}
}

// For backwards compatibility and tests.
Expand All @@ -149,8 +173,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `12`
// Estimated: `3477`
// Minimum execution time: 7_547_000 picoseconds.
Weight::from_parts(8_012_000, 3477)
// Minimum execution time: 8_451_000 picoseconds.
Weight::from_parts(8_707_000, 3477)
.saturating_add(RocksDbWeight::get().reads(3_u64))
.saturating_add(RocksDbWeight::get().writes(3_u64))
}
Expand All @@ -160,8 +184,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 2_474_000 picoseconds.
Weight::from_parts(2_745_000, 0)
// Minimum execution time: 3_241_000 picoseconds.
Weight::from_parts(3_468_000, 0)
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
/// Storage: `PositiveExternality::Validate` (r:1 w:0)
Expand All @@ -182,8 +206,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `220`
// Estimated: `3685`
// Minimum execution time: 31_769_000 picoseconds.
Weight::from_parts(33_039_000, 3685)
// Minimum execution time: 36_598_000 picoseconds.
Weight::from_parts(37_733_000, 3685)
.saturating_add(RocksDbWeight::get().reads(5_u64))
.saturating_add(RocksDbWeight::get().writes(6_u64))
}
Expand All @@ -203,8 +227,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `584`
// Estimated: `4049`
// Minimum execution time: 37_109_000 picoseconds.
Weight::from_parts(38_928_000, 4049)
// Minimum execution time: 42_221_000 picoseconds.
Weight::from_parts(43_722_000, 4049)
.saturating_add(RocksDbWeight::get().reads(6_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
}
Expand All @@ -218,9 +242,32 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `351`
// Estimated: `3816`
// Minimum execution time: 17_230_000 picoseconds.
Weight::from_parts(18_893_000, 3816)
// Minimum execution time: 21_238_000 picoseconds.
Weight::from_parts(22_268_000, 3816)
.saturating_add(RocksDbWeight::get().reads(3_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
/// Storage: `PositiveExternality::ValidationBlock` (r:1 w:0)
/// Proof: `PositiveExternality::ValidationBlock` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `SchellingGameShared::PeriodName` (r:1 w:0)
/// Proof: `SchellingGameShared::PeriodName` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `SchellingGameShared::DrawsInRound` (r:1 w:1)
/// Proof: `SchellingGameShared::DrawsInRound` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `SchellingGameShared::Nonce` (r:1 w:1)
/// Proof: `SchellingGameShared::Nonce` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `RandomnessCollectiveFlip::RandomMaterial` (r:1 w:0)
/// Proof: `RandomnessCollectiveFlip::RandomMaterial` (`max_values`: Some(1), `max_size`: Some(2594), added: 3089, mode: `MaxEncodedLen`)
/// Storage: `SortitionSumGame::SortitionSumTrees` (r:1 w:1)
/// Proof: `SortitionSumGame::SortitionSumTrees` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `SchellingGameShared::DrawnJurors` (r:1 w:1)
/// Proof: `SchellingGameShared::DrawnJurors` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn draw_jurors() -> Weight {
// Proof Size summary in bytes:
// Measured: `184048`
// Estimated: `187513`
// Minimum execution time: 3_418_748_000 picoseconds.
Weight::from_parts(3_594_238_000, 187513)
.saturating_add(RocksDbWeight::get().reads(7_u64))
.saturating_add(RocksDbWeight::get().writes(4_u64))
}
}

0 comments on commit 34e4569

Please sign in to comment.