Run Runtime Benchmarks on Block One (#5509)

* Run benchmarks on block 1

* Put example benchmarks behind feature flag

* add feature to cargo.toml

* typo

* Add `frame_system` trait bound

* Update instance benchmarks too
This commit is contained in:
Shawn Tabrizi
2020-04-03 16:29:59 +02:00
committed by GitHub
parent 76cf0ea6a6
commit 68169039ac
3 changed files with 52 additions and 36 deletions
+39 -33
View File
@@ -262,8 +262,7 @@ use frame_support::{
},
};
use sp_std::prelude::*;
use frame_benchmarking::{benchmarks, account};
use frame_system::{self as system, ensure_signed, ensure_root, RawOrigin};
use frame_system::{self as system, ensure_signed, ensure_root};
use codec::{Encode, Decode};
use sp_runtime::{
traits::{SignedExtension, Bounded, SaturatedConversion},
@@ -651,39 +650,46 @@ impl<T: Trait + Send + Sync> SignedExtension for WatchDummy<T> {
}
}
benchmarks!{
_ {
// Define a common range for `b`.
let b in 1 .. 1000 => ();
}
#[cfg(feature = "runtime-benchmarks")]
mod benchmarking {
use super::*;
use frame_benchmarking::{benchmarks, account};
use frame_system::RawOrigin;
// This will measure the execution time of `accumulate_dummy` for b in [1..1000] range.
accumulate_dummy {
let b in ...;
let caller = account("caller", 0, 0);
}: _ (RawOrigin::Signed(caller), b.into())
// This will measure the execution time of `set_dummy` for b in [1..1000] range.
set_dummy {
let b in ...;
let caller = account("caller", 0, 0);
}: set_dummy (RawOrigin::Signed(caller), b.into())
// This will measure the execution time of `set_dummy` for b in [1..10] range.
another_set_dummy {
let b in 1 .. 10;
let caller = account("caller", 0, 0);
}: set_dummy (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 {
m.push(i);
benchmarks!{
_ {
// Define a common range for `b`.
let b in 1 .. 1000 => ();
}
// This will measure the execution time of `accumulate_dummy` for b in [1..1000] range.
accumulate_dummy {
let b in ...;
let caller = account("caller", 0, 0);
}: _ (RawOrigin::Signed(caller), b.into())
// This will measure the execution time of `set_dummy` for b in [1..1000] range.
set_dummy {
let b in ...;
let caller = account("caller", 0, 0);
}: set_dummy (RawOrigin::Signed(caller), b.into())
// This will measure the execution time of `set_dummy` for b in [1..10] range.
another_set_dummy {
let b in 1 .. 10;
let caller = account("caller", 0, 0);
}: set_dummy (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 {
m.push(i);
}
}: {
m.sort();
}
}: {
m.sort();
}
}