Skip to content

Commit

Permalink
benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
jmg-duarte committed Dec 23, 2024
1 parent 52e398d commit 9638682
Show file tree
Hide file tree
Showing 3 changed files with 229 additions and 1 deletion.
127 changes: 127 additions & 0 deletions node/benchmark_template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
{{header}}
//! Autogenerated weights for `{{pallet}}`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION {{version}}
//! DATE: {{date}}, STEPS: `{{cmd.steps}}`, REPEAT: `{{cmd.repeat}}`, LOW RANGE: `{{cmd.lowest_range_values}}`, HIGH RANGE: `{{cmd.highest_range_values}}`
//! WORST CASE MAP SIZE: `{{cmd.worst_case_map_values}}`
//! HOSTNAME: `{{hostname}}`, CPU: `{{cpuname}}`
//! WASM-EXECUTION: `{{cmd.wasm_execution}}`, CHAIN: `{{cmd.chain}}`, DB CACHE: {{cmd.db_cache}}

// Executed Command:
{{#each args as |arg|}}
// {{arg}}
{{/each}}

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

use frame_support::{traits::Get, weights::Weight};
use core::marker::PhantomData;
use crate as {{pallet}};

trait WeightInfo {
{{#each benchmarks as |benchmark|}}
fn {{benchmark.name~}}(
{{~#each benchmark.components as |c| ~}}
{{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}}
) -> Weight;
{{/each}}
}

/// Weight functions for `{{pallet}}`.
pub struct Weights<T>(PhantomData<T>);
{{#if (eq pallet "frame_system_extensions")}}
impl<T: frame_system::Config> frame_system::ExtensionsWeightInfo for Weights<T> {
{{else}}
impl<T: frame_system::Config> {{pallet}}::WeightInfo for Weights<T> {
{{/if}}
{{#each benchmarks as |benchmark|}}
{{#each benchmark.comments as |comment|}}
/// {{comment}}
{{/each}}
{{#each benchmark.component_ranges as |range|}}
/// The range of component `{{range.name}}` is `[{{range.min}}, {{range.max}}]`.
{{/each}}
fn {{benchmark.name~}}
(
{{~#each benchmark.components as |c| ~}}
{{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}}
) -> Weight {
// Proof Size summary in bytes:
// Measured: `{{benchmark.base_recorded_proof_size}}{{#each benchmark.component_recorded_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}`
// Estimated: `{{benchmark.base_calculated_proof_size}}{{#each benchmark.component_calculated_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}`
// Minimum execution time: {{underscore benchmark.min_execution_time}}_000 picoseconds.
Weight::from_parts({{underscore benchmark.base_weight}}, 0)
.saturating_add(Weight::from_parts(0, {{benchmark.base_calculated_proof_size}}))
{{#each benchmark.component_weight as |cw|}}
// Standard Error: {{underscore cw.error}}
.saturating_add(Weight::from_parts({{underscore cw.slope}}, 0).saturating_mul({{cw.name}}.into()))
{{/each}}
{{#if (ne benchmark.base_reads "0")}}
.saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}}))
{{/if}}
{{#each benchmark.component_reads as |cr|}}
.saturating_add(T::DbWeight::get().reads(({{cr.slope}}_u64).saturating_mul({{cr.name}}.into())))
{{/each}}
{{#if (ne benchmark.base_writes "0")}}
.saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}}))
{{/if}}
{{#each benchmark.component_writes as |cw|}}
.saturating_add(T::DbWeight::get().writes(({{cw.slope}}_u64).saturating_mul({{cw.name}}.into())))
{{/each}}
{{#each benchmark.component_calculated_proof_size as |cp|}}
.saturating_add(Weight::from_parts(0, {{cp.slope}}).saturating_mul({{cp.name}}.into()))
{{/each}}
}
{{/each}}
}

{{#if (eq pallet "frame_system_extensions")}}
impl<T: frame_system::Config> frame_system::ExtensionsWeightInfo for () {
{{else}}
impl<T: frame_system::Config> {{pallet}}::WeightInfo for () {
{{/if}}
{{#each benchmarks as |benchmark|}}
{{#each benchmark.comments as |comment|}}
/// {{comment}}
{{/each}}
{{#each benchmark.component_ranges as |range|}}
/// The range of component `{{range.name}}` is `[{{range.min}}, {{range.max}}]`.
{{/each}}
fn {{benchmark.name~}}
(
{{~#each benchmark.components as |c| ~}}
{{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}}
) -> Weight {
use frame_support::constants::RocksDbWeight;

// Proof Size summary in bytes:
// Measured: `{{benchmark.base_recorded_proof_size}}{{#each benchmark.component_recorded_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}`
// Estimated: `{{benchmark.base_calculated_proof_size}}{{#each benchmark.component_calculated_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}`
// Minimum execution time: {{underscore benchmark.min_execution_time}}_000 picoseconds.
Weight::from_parts({{underscore benchmark.base_weight}}, 0)
.saturating_add(Weight::from_parts(0, {{benchmark.base_calculated_proof_size}}))
{{#each benchmark.component_weight as |cw|}}
// Standard Error: {{underscore cw.error}}
.saturating_add(Weight::from_parts({{underscore cw.slope}}, 0).saturating_mul({{cw.name}}.into()))
{{/each}}
{{#if (ne benchmark.base_reads "0")}}
.saturating_add(RocksDbWeight::get().reads({{benchmark.base_reads}}))
{{/if}}
{{#each benchmark.component_reads as |cr|}}
.saturating_add(RocksDbWeight::get().reads(({{cr.slope}}_u64).saturating_mul({{cr.name}}.into())))
{{/each}}
{{#if (ne benchmark.base_writes "0")}}
.saturating_add(RocksDbWeight::get().writes({{benchmark.base_writes}}))
{{/if}}
{{#each benchmark.component_writes as |cw|}}
.saturating_add(RocksDbWeight::get().writes(({{cw.slope}}_u64).saturating_mul({{cw.name}}.into())))
{{/each}}
{{#each benchmark.component_calculated_proof_size as |cp|}}
.saturating_add(Weight::from_parts(0, {{cp.slope}}).saturating_mul({{cp.name}}.into()))
{{/each}}
}
{{/each}}
}
14 changes: 13 additions & 1 deletion pallets/randomness/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,22 @@ mod benchmarks {
/// Instead of just adding the randomness value, it requires removing the oldest value too.
#[benchmark]
fn set_author_vrf() {
use frame_system::pallet_prelude::BlockNumberFor;

use crate::pallet::AuthorVrfHistory;

// Add 256 blocks so we trigger the remove into insert logic
for block_number in 0..=256u32 {
AuthorVrfHistory::<T>::insert::<BlockNumberFor<T>, T::Hash>(
block_number.into(),
Default::default(),
);
}

#[extrinsic_call]
_(RawOrigin::None);

let author_vrf = <T as crate::Config>::AuthorVrfGetter::get_author_vrf();
let author_vrf = T::AuthorVrfGetter::get_author_vrf();
assert!(author_vrf.is_some());
}

Expand Down
89 changes: 89 additions & 0 deletions pallets/randomness/weights.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@

//! Autogenerated weights for `pallet_randomness`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2024-12-23, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `parthenon`, CPU: `12th Gen Intel(R) Core(TM) i7-12700H`
//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: 1024
// Executed Command:
// target/release/polka-storage-node
// benchmark
// pallet
// --wasm-execution=compiled
// --pallet
// pallet_randomness
// --extrinsic
// *
// --steps
// 50
// --repeat
// 20
// --output
// pallets/randomness/weights.rs
// --template
// node/benchmark_template.hbs

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

use frame_support::{traits::Get, weights::Weight};
use core::marker::PhantomData;
use crate as pallet_randomness;

trait WeightInfo {
fn set_author_vrf() -> Weight;
}

/// Weight functions for `pallet_randomness`.
pub struct Weights<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_randomness::WeightInfo for Weights<T> {
/// Storage: `ParachainSystem::ValidationData` (r:1 w:0)
/// Proof: `ParachainSystem::ValidationData` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `ParachainSystem::RelayStateProof` (r:1 w:0)
/// Proof: `ParachainSystem::RelayStateProof` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `Randomness::CounterForAuthorVrfHistory` (r:1 w:0)
/// Proof: `Randomness::CounterForAuthorVrfHistory` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
/// Storage: `Randomness::AuthorVrfHistory` (r:1 w:1)
/// Proof: `Randomness::AuthorVrfHistory` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`)
/// Storage: `Randomness::AuthorVrf` (r:0 w:1)
/// Proof: `Randomness::AuthorVrf` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
fn set_author_vrf() -> Weight {
// Proof Size summary in bytes:
// Measured: `1052`
// Estimated: `3513`
// Minimum execution time: 16_315_000 picoseconds.
Weight::from_parts(17_210_000, 0)
.saturating_add(Weight::from_parts(0, 3513))
.saturating_add(T::DbWeight::get().reads(4))
.saturating_add(T::DbWeight::get().writes(2))
}
}

impl<T: frame_system::Config> pallet_randomness::WeightInfo for () {
/// Storage: `ParachainSystem::ValidationData` (r:1 w:0)
/// Proof: `ParachainSystem::ValidationData` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `ParachainSystem::RelayStateProof` (r:1 w:0)
/// Proof: `ParachainSystem::RelayStateProof` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `Randomness::CounterForAuthorVrfHistory` (r:1 w:0)
/// Proof: `Randomness::CounterForAuthorVrfHistory` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
/// Storage: `Randomness::AuthorVrfHistory` (r:1 w:1)
/// Proof: `Randomness::AuthorVrfHistory` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`)
/// Storage: `Randomness::AuthorVrf` (r:0 w:1)
/// Proof: `Randomness::AuthorVrf` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
fn set_author_vrf() -> Weight {
use frame_support::constants::RocksDbWeight;

// Proof Size summary in bytes:
// Measured: `1052`
// Estimated: `3513`
// Minimum execution time: 16_315_000 picoseconds.
Weight::from_parts(17_210_000, 0)
.saturating_add(Weight::from_parts(0, 3513))
.saturating_add(RocksDbWeight::get().reads(4))
.saturating_add(RocksDbWeight::get().writes(2))
}
}

0 comments on commit 9638682

Please sign in to comment.