Skip to content

Commit

Permalink
Adds base benchmark for do_tick in broker pallet (#1235)
Browse files Browse the repository at this point in the history
* Adds base benchmark for do_tick

* ".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime=dev --target_dir=substrate --pallet=pallet_broker

* Update substrate/frame/broker/src/benchmarking.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update substrate/frame/broker/src/benchmarking.rs

* ".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime=dev --target_dir=substrate --pallet=pallet_broker

* Addresses review comment

---------

Co-authored-by: command-bot <>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
  • Loading branch information
2 people authored and Daanvdplas committed Sep 11, 2023
1 parent 2ccc4f9 commit 5a1ad0d
Show file tree
Hide file tree
Showing 3 changed files with 239 additions and 156 deletions.
21 changes: 21 additions & 0 deletions substrate/frame/broker/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,27 @@ mod benches {
}
}

#[benchmark]
fn do_tick_base() -> Result<(), BenchmarkError> {
setup_and_start_sale::<T>()?;

advance_to::<T>(5);

let mut status = Status::<T>::get().unwrap();
status.last_committed_timeslice = 3;
Status::<T>::put(&status);

#[block]
{
Broker::<T>::do_tick();
}

let updated_status = Status::<T>::get().unwrap();
assert_eq!(status, updated_status);

Ok(())
}

// Implements a test for each benchmark. Execute with:
// `cargo test -p pallet-broker --features runtime-benchmarks`.
impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test);
Expand Down
7 changes: 4 additions & 3 deletions substrate/frame/broker/src/tick_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ impl<T: Config> Pallet<T> {
/// - Request revenue information for a previous timeslice
/// - Initialize an instantaneous core pool historical revenue record
pub(crate) fn do_tick() -> Weight {
let mut meter = WeightMeter::new();
meter.consume(T::WeightInfo::do_tick_base());

let (mut status, config) = match (Status::<T>::get(), Configuration::<T>::get()) {
(Some(s), Some(c)) => (s, c),
_ => return Weight::zero(),
_ => return meter.consumed(),
};

let mut meter = WeightMeter::new();

if Self::process_core_count(&mut status) {
meter.consume(T::WeightInfo::process_core_count(status.core_count.into()));
}
Expand Down
Loading

0 comments on commit 5a1ad0d

Please sign in to comment.