Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Extend the lower bounds of some of the benchmarks to also include 0 #12386

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions frame/alliance/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,8 +832,8 @@ benchmarks_instance_pallet! {
}

add_unscrupulous_items {
let n in 1 .. T::MaxUnscrupulousItems::get();
let l in 1 .. T::MaxWebsiteUrlLength::get();
let n in 0 .. T::MaxUnscrupulousItems::get();
let l in 0 .. T::MaxWebsiteUrlLength::get();

set_members::<T, I>();

Expand All @@ -856,8 +856,8 @@ benchmarks_instance_pallet! {
}

remove_unscrupulous_items {
let n in 1 .. T::MaxUnscrupulousItems::get();
let l in 1 .. T::MaxWebsiteUrlLength::get();
let n in 0 .. T::MaxUnscrupulousItems::get();
let l in 0 .. T::MaxWebsiteUrlLength::get();

set_members::<T, I>();

Expand Down
2 changes: 1 addition & 1 deletion frame/benchmarking/src/baseline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ benchmarks! {
}

sr25519_verification {
let i in 1 .. 100;
let i in 0 .. 100;

let public = SignerId::generate_pair(None);

Expand Down
10 changes: 7 additions & 3 deletions frame/bounties/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ benchmarks_instance_pallet! {
}

spend_funds {
let b in 1 .. 100;
let b in 0 .. 100;
setup_pot_account::<T, I>();
create_approved_bounties::<T, I>(b)?;

Expand All @@ -214,9 +214,13 @@ benchmarks_instance_pallet! {
);
}
verify {
ensure!(budget_remaining < BalanceOf::<T, I>::max_value(), "Budget not used");
ensure!(missed_any == false, "Missed some");
assert_last_event::<T, I>(Event::BountyBecameActive { index: b - 1 }.into())
if b > 0 {
ensure!(budget_remaining < BalanceOf::<T, I>::max_value(), "Budget not used");
assert_last_event::<T, I>(Event::BountyBecameActive { index: b - 1 }.into())
} else {
ensure!(budget_remaining == BalanceOf::<T, I>::max_value(), "Budget used");
}
}

impl_benchmark_test_suite!(Bounties, crate::tests::new_test_ext(), crate::tests::Test)
Expand Down
77 changes: 39 additions & 38 deletions frame/collective/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,68 +36,69 @@ fn assert_last_event<T: Config<I>, I: 'static>(generic_event: <T as Config<I>>::

benchmarks_instance_pallet! {
set_members {
let m in 1 .. T::MaxMembers::get();
let n in 1 .. T::MaxMembers::get();
let p in 1 .. T::MaxProposals::get();
let m in 0 .. T::MaxMembers::get();
let n in 0 .. T::MaxMembers::get();
let p in 0 .. T::MaxProposals::get();

// Set old members.
// We compute the difference of old and new members, so it should influence timing.
let mut old_members = vec![];
let mut last_old_member = account::<T::AccountId>("old member", 0, SEED);
for i in 0 .. m {
last_old_member = account::<T::AccountId>("old member", i, SEED);
old_members.push(last_old_member.clone());
let old_member = account::<T::AccountId>("old member", i, SEED);
old_members.push(old_member);
}
let old_members_count = old_members.len() as u32;

Collective::<T, I>::set_members(
SystemOrigin::Root.into(),
old_members.clone(),
Some(last_old_member.clone()),
old_members.last().cloned(),
T::MaxMembers::get(),
)?;

// Set a high threshold for proposals passing so that they stay around.
let threshold = m.max(2);
// Length of the proposals should be irrelevant to `set_members`.
let length = 100;
for i in 0 .. p {
// Proposals should be different so that different proposal hashes are generated
let proposal: T::Proposal = SystemCall::<T>::remark {
remark: vec![i as u8; length]
}.into();
Collective::<T, I>::propose(
SystemOrigin::Signed(last_old_member.clone()).into(),
threshold,
Box::new(proposal.clone()),
MAX_BYTES,
)?;
let hash = T::Hashing::hash_of(&proposal);
// Vote on the proposal to increase state relevant for `set_members`.
// Not voting for `last_old_member` because they proposed and not voting for the first member
// to keep the proposal from passing.
for j in 2 .. m - 1 {
let voter = &old_members[j as usize];
let approve = true;
Collective::<T, I>::vote(
SystemOrigin::Signed(voter.clone()).into(),
hash,
i,
approve,
// If there were any old members generate a bunch of proposals.
if m > 0 {
// Set a high threshold for proposals passing so that they stay around.
let threshold = m.max(2);
// Length of the proposals should be irrelevant to `set_members`.
let length = 100;
for i in 0 .. p {
// Proposals should be different so that different proposal hashes are generated
let proposal: T::Proposal = SystemCall::<T>::remark {
remark: vec![i as u8; length]
}.into();
Collective::<T, I>::propose(
SystemOrigin::Signed(old_members.last().unwrap().clone()).into(),
threshold,
Box::new(proposal.clone()),
MAX_BYTES,
)?;
let hash = T::Hashing::hash_of(&proposal);
// Vote on the proposal to increase state relevant for `set_members`.
// Not voting for last old member because they proposed and not voting for the first member
// to keep the proposal from passing.
for j in 2 .. m - 1 {
let voter = &old_members[j as usize];
let approve = true;
Collective::<T, I>::vote(
SystemOrigin::Signed(voter.clone()).into(),
hash,
i,
approve,
)?;
}
}
}

// Construct `new_members`.
// It should influence timing since it will sort this vector.
let mut new_members = vec![];
let mut last_member = account::<T::AccountId>("member", 0, SEED);
for i in 0 .. n {
last_member = account::<T::AccountId>("member", i, SEED);
new_members.push(last_member.clone());
let member = account::<T::AccountId>("member", i, SEED);
new_members.push(member);
}

}: _(SystemOrigin::Root, new_members.clone(), Some(last_member), T::MaxMembers::get())
}: _(SystemOrigin::Root, new_members.clone(), new_members.last().cloned(), T::MaxMembers::get())
verify {
new_members.sort();
assert_eq!(Collective::<T, I>::members(), new_members);
Expand Down
2 changes: 1 addition & 1 deletion frame/elections-phragmen/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ benchmarks! {
// total number of voters.
let v in (T::MaxVoters::get() / 2) .. T::MaxVoters::get();
// those that are defunct and need removal.
let d in 1 .. (T::MaxVoters::get() / 2);
let d in 0 .. (T::MaxVoters::get() / 2);

// remove any previous stuff.
clean::<T>();
Expand Down
8 changes: 4 additions & 4 deletions frame/examples/basic/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ use frame_system::RawOrigin;
// Details on using the benchmarks macro can be seen at:
// https://paritytech.github.io/substrate/master/frame_benchmarking/trait.Benchmarking.html#tymethod.benchmarks
benchmarks! {
// This will measure the execution time of `set_dummy` for b in [1..1000] range.
// This will measure the execution time of `set_dummy` for b in [0..1000] range.
set_dummy_benchmark {
// This is the benchmark setup phase
let b in 1 .. 1000;
let b in 0 .. 1000;
}: set_dummy(RawOrigin::Root, b.into()) // The execution phase is just running `set_dummy` extrinsic call
verify {
// This is the optional benchmark verification phase, asserting certain states.
assert_eq!(Pallet::<T>::dummy(), Some(b.into()))
}

// This will measure the execution time of `accumulate_dummy` for b in [1..1000] range.
// This will measure the execution time of `accumulate_dummy` for b in [0..1000] range.
// The benchmark execution phase is shorthanded. When the name of the benchmark case is the same
// as the extrinsic call. `_(...)` is used to represent the extrinsic name.
// The benchmark verification phase is omitted.
accumulate_dummy {
let b in 1 .. 1000;
let b in 0 .. 1000;
// The caller account is whitelisted for DB reads/write by the benchmarking macro.
let caller: T::AccountId = whitelisted_caller();
}: _(RawOrigin::Signed(caller), b.into())
Expand Down
4 changes: 2 additions & 2 deletions frame/gilt/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ benchmarks! {

pursue_target_per_item {
// bids taken
let b in 1..T::MaxQueueLen::get();
let b in 0..T::MaxQueueLen::get();

let caller: T::AccountId = whitelisted_caller();
T::Currency::make_free_balance_be(&caller, T::MinFreeze::get() * BalanceOf::<T>::from(b + 1));
Expand All @@ -113,7 +113,7 @@ benchmarks! {

pursue_target_per_queue {
// total queues hit
let q in 1..T::QueueCount::get();
let q in 0..T::QueueCount::get();

let caller: T::AccountId = whitelisted_caller();
T::Currency::make_free_balance_be(&caller, T::MinFreeze::get() * BalanceOf::<T>::from(q + 1));
Expand Down
24 changes: 12 additions & 12 deletions frame/identity/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ benchmarks! {

set_identity {
let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?;
let x in 1 .. T::MaxAdditionalFields::get();
let x in 0 .. T::MaxAdditionalFields::get();
let caller = {
// The target user
let caller: T::AccountId = whitelisted_caller();
Expand Down Expand Up @@ -166,7 +166,7 @@ benchmarks! {
set_subs_new {
let caller: T::AccountId = whitelisted_caller();
// Create a new subs vec with s sub accounts
let s in 1 .. T::MaxSubAccounts::get() => ();
let s in 0 .. T::MaxSubAccounts::get() => ();
let subs = create_sub_accounts::<T>(&caller, s)?;
ensure!(SubsOf::<T>::get(&caller).1.len() == 0, "Caller already has subs");
}: set_subs(RawOrigin::Signed(caller.clone()), subs)
Expand All @@ -177,7 +177,7 @@ benchmarks! {
set_subs_old {
let caller: T::AccountId = whitelisted_caller();
// Give them p many previous sub accounts.
let p in 1 .. T::MaxSubAccounts::get() => {
let p in 0 .. T::MaxSubAccounts::get() => {
let _ = add_sub_accounts::<T>(&caller, p)?;
};
// Remove all subs.
Expand All @@ -198,12 +198,12 @@ benchmarks! {
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());

let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?;
let s in 1 .. T::MaxSubAccounts::get() => {
let s in 0 .. T::MaxSubAccounts::get() => {
// Give them s many sub accounts
let caller: T::AccountId = whitelisted_caller();
let _ = add_sub_accounts::<T>(&caller, s)?;
};
let x in 1 .. T::MaxAdditionalFields::get();
let x in 0 .. T::MaxAdditionalFields::get();

// Create their main identity with x additional fields
let info = create_identity_info::<T>(x);
Expand Down Expand Up @@ -233,7 +233,7 @@ benchmarks! {
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());

let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?;
let x in 1 .. T::MaxAdditionalFields::get() => {
let x in 0 .. T::MaxAdditionalFields::get() => {
// Create their main identity with x additional fields
let info = create_identity_info::<T>(x);
let caller: T::AccountId = whitelisted_caller();
Expand All @@ -251,7 +251,7 @@ benchmarks! {
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());

let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?;
let x in 1 .. T::MaxAdditionalFields::get() => {
let x in 0 .. T::MaxAdditionalFields::get() => {
// Create their main identity with x additional fields
let info = create_identity_info::<T>(x);
let caller: T::AccountId = whitelisted_caller();
Expand Down Expand Up @@ -332,7 +332,7 @@ benchmarks! {
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());

let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?;
let x in 1 .. T::MaxAdditionalFields::get();
let x in 0 .. T::MaxAdditionalFields::get();

let info = create_identity_info::<T>(x);
let info_hash = T::Hashing::hash_of(&info);
Expand All @@ -348,8 +348,8 @@ benchmarks! {

kill_identity {
let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?;
let s in 1 .. T::MaxSubAccounts::get();
let x in 1 .. T::MaxAdditionalFields::get();
let s in 0 .. T::MaxSubAccounts::get();
let x in 0 .. T::MaxAdditionalFields::get();

let target: T::AccountId = account("target", 0, SEED);
let target_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(target.clone()).into();
Expand Down Expand Up @@ -379,7 +379,7 @@ benchmarks! {
}

add_sub {
let s in 1 .. T::MaxSubAccounts::get() - 1;
let s in 0 .. T::MaxSubAccounts::get() - 1;

let caller: T::AccountId = whitelisted_caller();
let _ = add_sub_accounts::<T>(&caller, s)?;
Expand Down Expand Up @@ -415,7 +415,7 @@ benchmarks! {
}

quit_sub {
let s in 1 .. T::MaxSubAccounts::get() - 1;
let s in 0 .. T::MaxSubAccounts::get() - 1;

let caller: T::AccountId = whitelisted_caller();
let sup = account("super", 0, SEED);
Expand Down
2 changes: 1 addition & 1 deletion frame/ranked-collective/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ benchmarks_instance_pallet! {
}

cleanup_poll {
let n in 1 .. 100;
let n in 0 .. 100;

// Create a poll
let class = T::Polls::classes().into_iter().next().unwrap();
Expand Down
11 changes: 6 additions & 5 deletions frame/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub fn create_validator_with_nominators<T: Config>(
points_total += 10;
points_individual.push((v_stash.clone(), 10));

let original_nominator_count = Nominators::<T>::count();
let mut nominators = Vec::new();

// Give the validator n nominators, but keep total users in the system the same.
Expand All @@ -114,7 +115,7 @@ pub fn create_validator_with_nominators<T: Config>(
assert_eq!(new_validators.len(), 1);
assert_eq!(new_validators[0], v_stash, "Our validator was not selected!");
assert_ne!(Validators::<T>::count(), 0);
assert_ne!(Nominators::<T>::count(), 0);
assert_eq!(Nominators::<T>::count(), original_nominator_count + nominators.len() as u32);

// Give Era Points
let reward = EraRewardPoints::<T::AccountId> {
Expand Down Expand Up @@ -544,7 +545,7 @@ benchmarks! {
}

payout_stakers_dead_controller {
let n in 1 .. T::MaxNominatorRewardedPerValidator::get() as u32;
let n in 0 .. T::MaxNominatorRewardedPerValidator::get() as u32;
let (validator, nominators) = create_validator_with_nominators::<T>(
n,
T::MaxNominatorRewardedPerValidator::get() as u32,
Expand Down Expand Up @@ -577,7 +578,7 @@ benchmarks! {
}