Skip to content

Instantly share code, notes, and snippets.

@Maar-io
Last active December 29, 2022 20:03
Show Gist options
  • Save Maar-io/3dc97f3d87a87c58885ea54628205ade to your computer and use it in GitHub Desktop.
Save Maar-io/3dc97f3d87a87c58885ea54628205ade to your computer and use it in GitHub Desktop.
Substrate pallet benchmarking (RMRK example)

Use this documentation on benchmarking. It is very good and will give all info you need.

To start existing benchmark tests I propose following steps:

  • rename pallets/rmrk-core/src/weights.rs to old_weights.rs. Just to keep it for referrence
  • examine the tests in benchmarks.rs files. They will produce measurements for the new weights.rs file
  • compile node with --features runtime-benchmarks
  • since rmrk node is missing production profile, use --profile=release in cargo build. Therefore instead of:
cd bin/node/cli
cargo build --profile=production --features runtime-benchmarks

use this:

cd bin/node/cli
cargo build --profile=release --features runtime-benchmarks
  • after building, run the node with:
./target/release/rmrk-substrate benchmark pallet \
    --chain dev \
    --execution=wasm \
    --wasm-execution=compiled \
    --pallet pallet_rmrk_core \
    --extrinsic "*" \
    --steps 50 \
    --repeat 20 \
    --output pallets/rmrk-core/src/weight.rs
  • this will generate new pallets/rmrk-core/src/weight.rs
  • compare old_weights.rs and newly genetated weights.rs. You will see missing trait and some renaming. This could be fixed with template file like this
    • I never found time to explore that and I mannualy changed that trait
  • check also runtime/src/lib file. in the pallet_rmrk_core there is now WeightInfo which points to this newly generated weights.rs file
type WeightInfo = pallet_rmrk_core::weights::SubstrateWeight<Runtime>;
  • you can also run all benchmark tests before building node:
cargo test --package pallet-rmrk-core --features runtime-benchmarks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment