pallet_example_mbm/migrations/v1/benchmarks.rs
1// This file is part of Substrate.
2
3// Copyright (C) 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//! Benchmark the multi-block-migration.
19
20#![cfg(feature = "runtime-benchmarks")]
21
22use crate::{
23 migrations::{
24 v1,
25 v1::{weights, weights::WeightInfo},
26 },
27 Config, Pallet,
28};
29use frame_benchmarking::v2::*;
30use frame_support::{migrations::SteppedMigration, weights::WeightMeter};
31
32#[benchmarks]
33mod benches {
34 use super::*;
35
36 /// Benchmark a single step of the `v1::LazyMigrationV1` migration.
37 #[benchmark]
38 fn step() {
39 v1::v0::MyMap::<T>::insert(0, 0);
40 let mut meter = WeightMeter::new();
41
42 #[block]
43 {
44 v1::LazyMigrationV1::<T, weights::SubstrateWeight<T>>::step(None, &mut meter).unwrap();
45 }
46
47 // Check that the new storage is decodable:
48 assert_eq!(crate::MyMap::<T>::get(0), Some(0));
49 // uses twice the weight once for migration and then for checking if there is another key.
50 assert_eq!(meter.consumed(), weights::SubstrateWeight::<T>::step() * 2);
51 }
52
53 impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Runtime);
54}