Skip to content
Snippets Groups Projects
Unverified Commit 1d351bf4 authored by Xavier Lau's avatar Xavier Lau Committed by GitHub
Browse files

Migrate pallet-election-provider-support-benchmarking benchmark to v2 (#6315)


Part of:

- #6202.

---------

Co-authored-by: default avatarGitHub Action <action@github.com>
Co-authored-by: default avatarGuillaume Thiolliere <guillaume.thiolliere@parity.io>
Co-authored-by: default avatarGiuseppe Re <giuseppe.re@parity.io>
Co-authored-by: default avatarGuillaume Thiolliere <gui.thiolliere@gmail.com>
parent 27bf54b4
No related merge requests found
Pipeline #504682 waiting for manual action with stages
in 35 minutes and 55 seconds
title: Migrate pallet-election-provider-support-benchmarking benchmark to v2
doc:
- audience: Runtime Dev
description: |-
Migrate pallet-election-provider-support-benchmarking benchmark to v2
crates:
- name: pallet-election-provider-support-benchmarking
bump: patch
......@@ -20,17 +20,19 @@
use alloc::vec::Vec;
use codec::Decode;
use frame_benchmarking::v1::benchmarks;
use frame_benchmarking::v2::*;
use frame_election_provider_support::{NposSolver, PhragMMS, SequentialPhragmen};
pub struct Pallet<T: Config>(frame_system::Pallet<T>);
pub trait Config: frame_system::Config {}
use sp_runtime::Perbill;
const VOTERS: [u32; 2] = [1_000, 2_000];
const TARGETS: [u32; 2] = [500, 1_000];
const VOTES_PER_VOTER: [u32; 2] = [5, 16];
const SEED: u32 = 999;
pub trait Config: frame_system::Config {}
pub struct Pallet<T: Config>(frame_system::Pallet<T>);
fn set_up_voters_targets<AccountId: Decode + Clone>(
voters_len: u32,
targets_len: u32,
......@@ -54,36 +56,47 @@ fn set_up_voters_targets<AccountId: Decode + Clone>(
(voters, targets)
}
benchmarks! {
phragmen {
// number of votes in snapshot.
let v in (VOTERS[0]) .. VOTERS[1];
// number of targets in snapshot.
let t in (TARGETS[0]) .. TARGETS[1];
// number of votes per voter (ie the degree).
let d in (VOTES_PER_VOTER[0]) .. VOTES_PER_VOTER[1];
let (voters, targets) = set_up_voters_targets::<T::AccountId>(v, t, d as usize);
}: {
assert!(
SequentialPhragmen::<T::AccountId, sp_runtime::Perbill>
::solve(d as usize, targets, voters).is_ok()
);
#[benchmarks]
mod benchmarks {
use super::*;
#[benchmark]
fn phragmen(
// Number of votes in snapshot.
v: Linear<{ VOTERS[0] }, { VOTERS[1] }>,
// Number of targets in snapshot.
t: Linear<{ TARGETS[0] }, { TARGETS[1] }>,
// Number of votes per voter (ie the degree).
d: Linear<{ VOTES_PER_VOTER[0] }, { VOTES_PER_VOTER[1] }>,
) {
let (voters, targets) = set_up_voters_targets::<T::AccountId>(v, t, d as _);
let result;
#[block]
{
result = SequentialPhragmen::<T::AccountId, Perbill>::solve(d as _, targets, voters);
}
assert!(result.is_ok());
}
phragmms {
// number of votes in snapshot.
let v in (VOTERS[0]) .. VOTERS[1];
// number of targets in snapshot.
let t in (TARGETS[0]) .. TARGETS[1];
// number of votes per voter (ie the degree).
let d in (VOTES_PER_VOTER[0]) .. VOTES_PER_VOTER[1];
let (voters, targets) = set_up_voters_targets::<T::AccountId>(v, t, d as usize);
}: {
assert!(
PhragMMS::<T::AccountId, sp_runtime::Perbill>
::solve(d as usize, targets, voters).is_ok()
);
#[benchmark]
fn phragmms(
// Number of votes in snapshot.
v: Linear<{ VOTERS[0] }, { VOTERS[1] }>,
// Number of targets in snapshot.
t: Linear<{ TARGETS[0] }, { TARGETS[1] }>,
// Number of votes per voter (ie the degree).
d: Linear<{ VOTES_PER_VOTER[0] }, { VOTES_PER_VOTER[1] }>,
) {
let (voters, targets) = set_up_voters_targets::<T::AccountId>(v, t, d as _);
let result;
#[block]
{
result = PhragMMS::<T::AccountId, Perbill>::solve(d as _, targets, voters);
}
assert!(result.is_ok());
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment