Skip to content
Snippets Groups Projects
Unverified Commit a4e366da authored by bgallois's avatar bgallois
Browse files

add pallet-quota benchmarks

parent b793b455
No related branches found
No related tags found
No related merge requests found
...@@ -19,46 +19,93 @@ ...@@ -19,46 +19,93 @@
use super::*; use super::*;
use frame_benchmarking::{account, benchmarks}; use frame_benchmarking::{account, benchmarks};
// FIXME this is a naïve implementation of benchmarks: fn assert_has_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
// - without properly prepare data frame_system::Pallet::<T>::assert_has_event(generic_event.into());
// - without "verify" blocks }
// - without thinking about worst case scenario
// - without writing complexity in the term of refund queue length
// It's there as a seed for benchmark implementation and to use WeightInfo where needed.
benchmarks! { benchmarks! {
where_clause { where_clause {
where where
IdtyId<T>: From<u32>, IdtyId<T>: From<u32>,
BalanceOf<T>: From<u64>, BalanceOf<T>: From<u64>,
T::AccountId: From<[u8; 32]>,
} }
queue_refund { queue_refund {
let account: T::AccountId = account("Alice", 1, 1); let account: T::AccountId = account("Alice", 1, 1);
let dummy_refund = Refund {
account: account.clone(),
identity: 0u32.into(),
amount: 20u64.into(),
};
let refund = Refund { let refund = Refund {
account, account,
identity: 1u32.into(), identity: 1u32.into(),
amount: 10u64.into(), amount: 10u64.into(),
}; };
}: { Pallet::<T>::queue_refund(refund) } // Complexity is bound to MAX_QUEUD_REFUNDS where an insertion is O(n-1)
for i in 0..MAX_QUEUED_REFUNDS-1 {
Pallet::<T>::queue_refund(dummy_refund.clone())
}
}: { Pallet::<T>::queue_refund(refund.clone()) }
verify {
assert_eq!(RefundQueue::<T>::get().last(), Some(refund).as_ref());
assert_eq!(RefundQueue::<T>::get().len() as u32, MAX_QUEUED_REFUNDS);
}
spend_quota { spend_quota {
let idty_id = 1u32; let idty_id: IdtyId<T> = 1u32.into();
let amount = 1u64; let amount = 2u64;
IdtyQuota::<T>::insert(
idty_id,
Quota {
last_use: T::BlockNumber::zero(),
amount: 10u64.into(),
},
);
}: { Pallet::<T>::spend_quota(idty_id.into(), amount.into()) } }: { Pallet::<T>::spend_quota(idty_id.into(), amount.into()) }
verify {
// Initially 10, updated to 11, minus 2
assert_eq!(IdtyQuota::<T>::get(idty_id).unwrap().amount, 9u64.into());
}
try_refund { try_refund {
let account: T::AccountId = account("Alice", 1, 1); let account: T::AccountId = account("Alice", 1, 1);
let idty_id: IdtyId<T> = 1u32.into();
IdtyQuota::<T>::insert(
idty_id,
Quota {
last_use: T::BlockNumber::zero(),
amount: 10u64.into(),
},
);
let _ = CurrencyOf::<T>:: make_free_balance_be(
&T::RefundAccount::get(),u32::MAX.into(),
);
// The worst-case scenario is when the refund fails
// and can only be triggered if the account is dead,
// in this case by having no balance in the account.
let refund = Refund { let refund = Refund {
account, account: account.clone(),
identity: 1u32.into(), identity: 1u32.into(),
amount: 10u64.into(), amount: 10u64.into(),
}; };
}: { Pallet::<T>::try_refund(refund) } }: { Pallet::<T>::try_refund(refund) }
verify {
assert_has_event::<T>(Event::<T>::RefundFailed ( account ).into());
}
do_refund { do_refund {
let account: T::AccountId = account("Alice", 1, 1); let account: T::AccountId = account("Alice", 1, 1);
let _ = CurrencyOf::<T>:: make_free_balance_be(
&T::RefundAccount::get(),u32::MAX.into(),
);
// The worst-case scenario is when the refund fails
// and can only be triggered if the account is dead,
// in this case by having no balance in the account.
let refund = Refund { let refund = Refund {
account, account: account.clone(),
identity: 1u32.into(), identity: 1u32.into(),
amount: 10u64.into(), amount: 10u64.into(),
}; };
let amount = 5u64.into(); }: { Pallet::<T>::try_refund(refund) }
}: { Pallet::<T>::do_refund(refund, amount) } verify {
assert_has_event::<T>(Event::<T>::RefundFailed ( account ).into());
}
} }
// Copyright 2021-2022 Axiom-Team
//
// This file is part of Duniter-v2S.
//
// Duniter-v2S is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Duniter-v2S is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
//! Autogenerated weights for `pallet_quota` //! Autogenerated weights for `pallet_quota`
//! //!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-10-26, STEPS: `5`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! DATE: 2023-11-15, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000` //! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `Albatros`, CPU: `Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz` //! HOSTNAME: `bgallois-ms7d43`, CPU: `12th Gen Intel(R) Core(TM) i3-12100F`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("gdev-benchmark"), DB CACHE: 1024 //! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
// Executed Command: // Executed Command:
// ./target/debug/duniter // ./target/release/duniter
// benchmark // benchmark
// pallet // pallet
// --chain=gdev-benchmark // --chain
// --steps=5 // dev
// --repeat=2
// --pallet=pallet_quota
// --extrinsic=*
// --execution=wasm
// --wasm-execution=compiled // --wasm-execution=compiled
// --heap-pages=4096 // --pallet
// --output=./ // pallet-quota
// --header=./file_header.txt // --extrinsic
// *
// --steps
// 50
// --repeat
// 20
// --output=runtime/common/src/weights/
#![cfg_attr(rustfmt, rustfmt_skip)] #![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)] #![allow(unused_parens)]
...@@ -52,10 +39,10 @@ impl<T: frame_system::Config> pallet_quota::WeightInfo for WeightInfo<T> { ...@@ -52,10 +39,10 @@ impl<T: frame_system::Config> pallet_quota::WeightInfo for WeightInfo<T> {
/// Proof: Quota RefundQueue (max_values: Some(1), max_size: Some(11266), added: 11761, mode: MaxEncodedLen) /// Proof: Quota RefundQueue (max_values: Some(1), max_size: Some(11266), added: 11761, mode: MaxEncodedLen)
fn queue_refund() -> Weight { fn queue_refund() -> Weight {
// Proof Size summary in bytes: // Proof Size summary in bytes:
// Measured: `42` // Measured: `11288`
// Estimated: `12751` // Estimated: `12751`
// Minimum execution time: 73_265_000 picoseconds. // Minimum execution time: 7_039_000 picoseconds.
Weight::from_parts(77_698_000, 0) Weight::from_parts(7_295_000, 0)
.saturating_add(Weight::from_parts(0, 12751)) .saturating_add(Weight::from_parts(0, 12751))
.saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1)) .saturating_add(T::DbWeight::get().writes(1))
...@@ -64,32 +51,40 @@ impl<T: frame_system::Config> pallet_quota::WeightInfo for WeightInfo<T> { ...@@ -64,32 +51,40 @@ impl<T: frame_system::Config> pallet_quota::WeightInfo for WeightInfo<T> {
/// Proof: Quota IdtyQuota (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) /// Proof: Quota IdtyQuota (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen)
fn spend_quota() -> Weight { fn spend_quota() -> Weight {
// Proof Size summary in bytes: // Proof Size summary in bytes:
// Measured: `137` // Measured: `139`
// Estimated: `3489` // Estimated: `3489`
// Minimum execution time: 147_746_000 picoseconds. // Minimum execution time: 3_382_000 picoseconds.
Weight::from_parts(165_850_000, 0) Weight::from_parts(3_655_000, 0)
.saturating_add(Weight::from_parts(0, 3489)) .saturating_add(Weight::from_parts(0, 3489))
.saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1)) .saturating_add(T::DbWeight::get().writes(1))
} }
/// Storage: Quota IdtyQuota (r:1 w:1) /// Storage: Quota IdtyQuota (r:1 w:1)
/// Proof: Quota IdtyQuota (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) /// Proof: Quota IdtyQuota (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen)
/// Storage: System Account (r:1 w:0)
/// Proof: System Account (max_values: None, max_size: Some(126), added: 2601, mode: MaxEncodedLen)
fn try_refund() -> Weight { fn try_refund() -> Weight {
// Proof Size summary in bytes: // Proof Size summary in bytes:
// Measured: `137` // Measured: `139`
// Estimated: `3489` // Estimated: `3591`
// Minimum execution time: 367_239_000 picoseconds. // Minimum execution time: 11_210_000 picoseconds.
Weight::from_parts(392_186_000, 0) Weight::from_parts(11_612_000, 0)
.saturating_add(Weight::from_parts(0, 3489)) .saturating_add(Weight::from_parts(0, 3591))
.saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(1)) .saturating_add(T::DbWeight::get().writes(1))
} }
/// Storage: Quota IdtyQuota (r:1 w:1)
/// Proof: Quota IdtyQuota (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen)
/// Storage: System Account (r:1 w:0)
/// Proof: System Account (max_values: None, max_size: Some(126), added: 2601, mode: MaxEncodedLen)
fn do_refund() -> Weight { fn do_refund() -> Weight {
// Proof Size summary in bytes: // Proof Size summary in bytes:
// Measured: `0` // Measured: `139`
// Estimated: `0` // Estimated: `3591`
// Minimum execution time: 356_707_000 picoseconds. // Minimum execution time: 11_220_000 picoseconds.
Weight::from_parts(471_930_000, 0) Weight::from_parts(11_589_000, 0)
.saturating_add(Weight::from_parts(0, 0)) .saturating_add(Weight::from_parts(0, 3591))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(1))
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment