Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
34853d2
Trying to benchmark pallet-example
jimmychu0807 Feb 28, 2021
19ff8c4
added the weights info in function
jimmychu0807 Mar 2, 2021
6e5902a
updated naming
jimmychu0807 Mar 8, 2021
c4c0376
updated with benchmarking and weight
jimmychu0807 Mar 9, 2021
86a3333
Merge branch 'master' into jc/example-benchmarking
jimmychu0807 Mar 9, 2021
2a3ea00
Updated test for pallet-example
jimmychu0807 Mar 9, 2021
3d68f86
adding weights.rs benchmarked in release mode
jimmychu0807 Mar 9, 2021
c436b14
Removed pallet-example from node-runtime
jimmychu0807 Mar 9, 2021
3ab9102
adjusted
jimmychu0807 Mar 9, 2021
8d2cdf9
modification based on peer comments
jimmychu0807 Mar 12, 2021
abd4507
updated so far
jimmychu0807 Mar 19, 2021
ef98f05
Merge branch 'master' into jc/example-benchmarking
jimmychu0807 Mar 19, 2021
7614873
updated
jimmychu0807 Mar 20, 2021
911fdcc
updated
jimmychu0807 Mar 20, 2021
a291e13
updated code
jimmychu0807 Mar 25, 2021
612cde9
Added explanation on impl_benchmark_test_suite! macro
jimmychu0807 Mar 25, 2021
f4ff4f7
Remove pallet-example from runtime
jimmychu0807 Mar 25, 2021
8c66979
Merge remote-tracking branch 'gh-parity/master' into jc/example-bench…
jimmychu0807 Mar 25, 2021
a103aca
rm pallet-example
jimmychu0807 Mar 25, 2021
f28e430
Update frame/example/src/benchmarking.rs
Mar 29, 2021
a697b9a
Merge remote-tracking branch 'gh-parity/master' into jc/example-bench…
jimmychu0807 Mar 29, 2021
60b614d
additional comment on manually configuring weight
jimmychu0807 Mar 29, 2021
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
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frame/elections-phragmen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ mod tests {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type SS58Prefix = ();
}

parameter_types! {
Expand Down
9 changes: 5 additions & 4 deletions frame/example/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pallet-example"
version = "2.0.0"
version = "3.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
license = "Unlicense"
Expand All @@ -21,23 +21,24 @@ pallet-balances = { version = "3.0.0", default-features = false, path = "../bala
sp-runtime = { version = "3.0.0", default-features = false, path = "../../primitives/runtime" }
sp-std = { version = "3.0.0", default-features = false, path = "../../primitives/std" }
sp-io = { version = "3.0.0", default-features = false, path = "../../primitives/io" }

frame-benchmarking = { version = "3.1.0", default-features = false, path = "../benchmarking", optional = true }
log = { version = "0.4.14", default-features = false }

[dev-dependencies]
sp-core = { version = "3.0.0", path = "../../primitives/core", default-features = false }

[features]
default = ["std"]
std = [
"serde",
"codec/std",
"sp-runtime/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"log/std",
"pallet-balances/std",
"serde",
"sp-io/std",
"sp-runtime/std",
"sp-std/std"
]
runtime-benchmarks = ["frame-benchmarking"]
Expand Down
76 changes: 76 additions & 0 deletions frame/example/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// This file is part of Substrate.

// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Benchmarking for pallet-example.

#![cfg(feature = "runtime-benchmarks")]

use crate::*;
use frame_benchmarking::{benchmarks, whitelisted_caller, impl_benchmark_test_suite};
use frame_system::RawOrigin;

// To actually run this benchmark on pallet-example, we need to put this pallet into the
// runtime and compile it with `runtime-benchmarks` feature. The detail procedures are
// documented at:
// https://substrate.dev/docs/en/knowledgebase/runtime/benchmarking#how-to-benchmark
//
// The auto-generated weight estimate of this pallet is copied over to the `weights.rs` file.
// The exact command of how the estimate generated is printed at the top of the file.

// Details on using the benchmarks macro can be seen at:
// https://substrate.dev/rustdocs/v3.0.0/frame_benchmarking/macro.benchmarks.html
benchmarks!{
// This will measure the execution time of `set_dummy` for b in [1..1000] range.
set_dummy_benchmark {
// This is the benchmark setup phase
let b in 1 .. 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.
// 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;
// The caller account is whitelisted for DB reads/write by the benchmarking macro.
let caller: T::AccountId = whitelisted_caller();
}: _(RawOrigin::Signed(caller), b.into())

// This will measure the execution time of sorting a vector.
sort_vector {
let x in 0 .. 10000;
let mut m = Vec::<u32>::new();
for i in (0..x).rev() {
m.push(i);
}
}: {
// The benchmark execution phase could also be a closure with custom code
m.sort();
}
}

// This line generates test cases for benchmarking, and could be run by:
// `cargo test -p pallet-example --all-features`, you will see an additional line of:
// `test benchmarking::benchmark_tests::test_benchmarks ... ok` in the result.
//
// The line generates three steps per benchmark, with repeat=1 and the three steps are
// [low, mid, high] of the range.
impl_benchmark_test_suite!(Pallet, crate::tests::new_test_ext(), crate::tests::Test);
Loading