Skip to content

Commit fb80afd

Browse files
authored
WeightInfo for System, Timestamp, and Utility (#6868)
* initial updates to system * fix compile * Update writer.rs * update weights * finish system weights * timestamp weights * utility weight * Fix overflow in weight calculations * add back weight notes * Update for whitelisted benchmarks * add trait bounds * Revert "add trait bounds" This reverts commit 12b08b7189aa3969f96fa19b211a370860fdb240. * Update weights for unaccounted for read
1 parent 0419f25 commit fb80afd

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

src/default_weights.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// This file is part of Substrate.
2+
3+
// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
4+
// SPDX-License-Identifier: Apache-2.0
5+
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
18+
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0-rc5
19+
20+
#![allow(unused_parens)]
21+
22+
use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight};
23+
24+
impl crate::WeightInfo for () {
25+
// WARNING! Some components were not used: ["t"]
26+
fn set() -> Weight {
27+
(9133000 as Weight)
28+
.saturating_add(DbWeight::get().reads(2 as Weight))
29+
.saturating_add(DbWeight::get().writes(1 as Weight))
30+
}
31+
// WARNING! Some components were not used: ["t"]
32+
fn on_finalize() -> Weight {
33+
(5915000 as Weight)
34+
}
35+
}

src/lib.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
#![cfg_attr(not(feature = "std"), no_std)]
9494

9595
mod benchmarking;
96+
mod default_weights;
9697

9798
use sp_std::{result, cmp};
9899
use sp_inherents::{ProvideInherent, InherentData, InherentIdentifier};
@@ -116,13 +117,8 @@ use sp_timestamp::{
116117
};
117118

118119
pub trait WeightInfo {
119-
fn set(t: u32, ) -> Weight;
120-
fn on_finalize(t: u32, ) -> Weight;
121-
}
122-
123-
impl WeightInfo for () {
124-
fn set(_t: u32, ) -> Weight { 1_000_000_000 }
125-
fn on_finalize(_t: u32, ) -> Weight { 1_000_000_000 }
120+
fn set() -> Weight;
121+
fn on_finalize() -> Weight;
126122
}
127123

128124
/// The module configuration trait
@@ -166,12 +162,9 @@ decl_module! {
166162
/// - `O(T)` where `T` complexity of `on_timestamp_set`
167163
/// - 1 storage read and 1 storage mutation (codec `O(1)`). (because of `DidUpdate::take` in `on_finalize`)
168164
/// - 1 event handler `on_timestamp_set` `O(T)`.
169-
/// - Benchmark: 7.678 (min squares analysis)
170-
/// - NOTE: This benchmark was done for a runtime with insignificant `on_timestamp_set` handlers.
171-
/// New benchmarking is needed when adding new handlers.
172165
/// # </weight>
173166
#[weight = (
174-
T::DbWeight::get().reads_writes(2, 1) + 8_000_000,
167+
T::WeightInfo::set(),
175168
DispatchClass::Mandatory
176169
)]
177170
fn set(origin, #[compact] now: T::Moment) {
@@ -191,13 +184,12 @@ decl_module! {
191184
/// dummy `on_initialize` to return the weight used in `on_finalize`.
192185
fn on_initialize() -> Weight {
193186
// weight of `on_finalize`
194-
5_000_000
187+
T::WeightInfo::on_finalize()
195188
}
196189

197190
/// # <weight>
198191
/// - `O(1)`
199192
/// - 1 storage deletion (codec `O(1)`).
200-
/// - Benchmark: 4.928 µs (min squares analysis)
201193
/// # </weight>
202194
fn on_finalize() {
203195
assert!(<Self as Store>::DidUpdate::take(), "Timestamp must be updated once in the block");

0 commit comments

Comments
 (0)